PHPを使用して画像をダウンロードする際の500内部サーバーエラー
-
27-10-2019 - |
質問
一度にDB 80の画像をダウンロードして挿入しているにもかかわらず、次のスクリプトを実行して500の内部サーバーエラーを取得します。
<?php
function download_remote_file($file_url, $save_to)
{
$content = file_get_contents($file_url);
file_put_contents($save_to, $content);
}
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
require_once('sqlconnect.php');
$time_start = microtime_float();
$query="SELECT * FROM GAMES WHERE GAME_IMAGE LIKE '%cache%' LIMIT 0, 80";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$game_img = $row['GAME_IMAGE'];
$gameDB_id = $row['GAME_DBID'];
chdir($_SERVER['DOCUMENT_ROOT'].'/img/game/');
if(!file_exists($gameDB_id))
{
mkdir($gameDB_id);
}
if(strlen(strstr($game_img,'boxart')) == 0)
{
$game_img = $game_img.'/boxart/original/front/'.$gameDB_id.'-1.jpg';
}
$game_img_path = $_SERVER['DOCUMENT_ROOT'].'/img/game/'.$gameDB_id;
chmod($game_img_path,0777);
$game_img_name = $gameDB_id.'.jpg';
$gamefullpath = 'http://www.someSite.nl/img/game/'.$gameDB_id.'/'.$game_img_name;
if(!file_exists($game_img_path.'/'.$game_img_name ))
{
download_remote_file($game_img, realpath($game_img_path) . '/'.$game_img_name);
$bytes = filesize($game_img_path.'/'.$game_img_name );
$KB = round($bytes / 1024, 2);
if($KB > 50)
{
echo "The ID number ".$gameDB_id. " has an invalid image URL, look it up on gamedb.net! <br />";
}
}
$query2 = "UPDATE GAMES SET GAME_IMAGE = '$gamefullpath' WHERE GAME_DBID = '$gameDB_id' AND GAME_DBID";
$result2 = mysql_query($query2) or die("error!");
//$nr_of_files = count($game_img_path);
//echo "Nr of images downloaded:".$nr_of_files;
}
mysql_close($con);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Downloading and adding to the database took ".$time." seconds <br />";
$message = "The specified images have been downloaded!";
echo $message;
?>
私はサーバーが停止するように強制するために何か間違ったことをしていますか?または、それが効率的ではない場合に備えて、私がそれを作るために何ができるか。または、問題はサーバー構成です。
サーバ:
Apache/2.2.9 (Debian) DAV/2 SVN/1.5.1 PHP/5.2.6-1+lenny13 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.7(2008-08-11) mod_ssl/2.2.9 OpenSSL/0.9.8g Server
あなたの助けは大歓迎です。
更新(ログ):
[Wed Jan 11 08:58:39 2012] [notice] mod_fcgid: call /home/someSiteName/public_html/admin/download_game_img.php with wrapper /home/someSiteName/fcgi-bin/php5.fcgi
更新(時間):
約100秒。
更新(die):
私はこのラインの後にダイを置きました、そして、エラーはここにあるようです:
download_remote_file($game_img, realpath($game_img_path) . '/'.$game_img_name);
解決
これは、デフォルトのPHPスクリプトの最大実行時間が 30秒 そして、あなたのページには100秒以上かかります。
.htaccessファイルを使用して、PHPスクリプトの最大実行時間を増やすことができます
次の行をあなたに追加します .htaccess ファイル
php_value max_execution_time 8000
php_value max_input_time 4000
制限を設定することもできます php.ini ファイル
max_execution_time 8000
max_input_time 4000
所属していません StackOverflow