현재 로그 파일을 읽고 MySQL 데이터베이스에 데이터를 저장할 수있는 간단한 PHP 스크립트를 작성하고 있습니다. 이 과정에서 사이트에 웹 요청을 보내서 MySQL 데이터베이스에 삽입되는 일부 데이터를 제공합니다. 나는 그것을 500 개의 레코드를 삽입하고 나서 내 홈페이지로 리다이렉트 할 것을 기대해야하지만, 서버 에러로 끝나고 데이터베이스를 점검 할 때 약 65-70 레코드 만 입력한다. 스크립트가 더 적은 수의 레코드로 작동하므로 로그 파일에 문제가 없는지 확인했습니다. 제발 도와주세요. GeoIP가의 부분에 대한 제한에 따라(PHP + MySQL) 65 번째 레코드에서 항상 서버 오류가 발생합니다.
<?php
//Make a connection
$connection = mysql_connect("localhost:3306", "root", "XXXXXXXX");
//Select a table
$db_select = mysql_select_db("major_project", $connection);
//open file
$report = fopen('C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\HN.F\report.txt', 'r') or exit("Unable to open report.txt");
//insert operation
while(!feof($report))
{
$array = explode("\t", fgets($report));
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $dest, $destp, $ser) = $array;
if($seg != 'Segment')
{
if(count($array) == 12)
{
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $dest, $destp, $ser) = $array;
$ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$source, 'r');
while(!feof($ipaddrloc))
{
$var = fgets($ipaddrloc);
$lat = json_decode($var)->latitude;
$long = json_decode($var)->longitude;
$country = json_decode($var)->countryname;
$city = json_decode($var)->city;
}
mysql_query("INSERT INTO `major_project`.`logs` (`LOG_NUMBER`, `Segment`, `Timestamp`, `Rule`, `Severity`, `Reference system`, `Reference`, `Source`, `Source port`, `Dest.`, `Dest. port`, `Service`, `Country`, `City`, `Latitude`, `Longitude`) VALUES (null, '$seg', '$ts', '$rule', '$sev', '$ref', '$ref2', '$source', '$sourcep', '$dest', '$destp', '$ser', '$country', '$city', '$lat', '$long')");
}
else
{
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $flag, $dest, $destp, $ser) = $array;
$ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$source, 'r');
while(!feof($ipaddrloc))
{
$var = fgets($ipaddrloc);
$lat = json_decode($var)->latitude;
$long = json_decode($var)->longitude;
$country = json_decode($var)->countryname;
$city = json_decode($var)->city;
}
mysql_query("INSERT INTO `major_project`.`logs` (`LOG_NUMBER`, `Segment`, `Timestamp`, `Rule`, `Severity`, `Reference system`, `Reference`, `Source`, `Source port`, `Flag`, `Dest.`, `Dest. port`, `Service`, `Country`, `City`, `Latitude`, `Longitude`) VALUES (null, '$seg', '$ts', '$rule', '$sev', '$ref', '$ref2', '$source', '$sourcep', '$flag', '$dest', '$destp', '$ser', '$country', '$city', '$lat', '$long')");
}
}
}
header("Location: startpage.html");
?>
코드를 오류보다 붙여 넣는 것이 더 유용합니다. –
500이면, 더 많이 알려줄 수있는'error.log'가 있습니다. 당신은 그것에 접근 할 수 있습니까? –
하지만 Appspot의 끝 부분에 요청 제한을 두는 것이 좋습니다. 요청을 삭제해도 작동합니까? –