私は現在、ログファイルを読み込んでデータをMySQLデータベースに入れるための簡単なPHPスクリプトを作成しています。その間、MySQLデータベースにも挿入されているデータをサイトに要求してくれます。 500レコードを挿入してホームページにリダイレクトすると予想されますが、サーバーエラーで終わります。データベースをチェックすると、約65-70レコードしか入力されません。チェックしたところ、ログファイルに問題はありません。スクリプトは少数のレコードで動作します。助けてください。ただ(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の終わりにいくつかのリクエスト制限を打つことを確信しています。そのリクエストを削除すると機能しますか? –