preg_match ile log dosyasindan cekdigim verileri mysql databanka yüklemek istiyorum.
Sorunum surda:
Log'da sadece yeni verileri mysql'e eklemesini istiyorum. Bu islemi nasil yapabilirim?
Suan kullandigim script bu:
$ac_arr = file('/usr/local/server/logs/in.log');
$astring = join("", $ac_arr);
$astring = preg_replace("//", "", $astring);
$records = preg_split("/ip-([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)-ip/", $astring, -1, PREG_SPLIT_DELIM_CAPTURE);
$sizerecs = sizeof($records);
// now split into records
$i = 1;
$each_rec = 0;
while($i<$sizerecs) {
$ip = $records[$i];
$all = $records[$i+1];
// parse other fields
preg_match("/time-(.*)......-time/", $all, $match);
$access_time = $match[1];
preg_match("/status-(.*?)-status/", $all, $match);
$success_code = $match[1];
preg_match("/useragent-(.*?)-useragent/", $all, $match);
$useragent = $match[1];
preg_match("/bandt-([0-9]+\b)-bandt/", $all, $match);
$bytes = $match[1];
preg_match("/user-(.*?)-user/", $all, $match);
$user = $match[1];
preg_match("/port-(.*?)-port/", $all, $match);
$channel = $match[1];
// advance to next record
$i = $i + 2;
$each_rec++;