注: これはパフォーマンスに関する質問です
mysql データベースに 20,000 の画像 URL があり、画像 URL が有効で壊れていないかどうかを確認するために 1 分間隔で cron を実行しています。EC2 small で実行しています。@GetImageSize などのメソッドを試して、ヘッダーと cURL をチェックしましたが、ジョブに最大 10 分かかります。画像をダウンロードする必要がなく、非常に高速な方法があるかどうかを知りたいです。
ループ内の約25枚の画像に対する以下の提案(クレジットと称賛)からのいくつかのテストを次に示します。
function method2($link){ //45sec
if (@GetImageSize($link)) {
echo "image exists ";
}
}
function method4($url){ //13 sec
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE) {
echo "image exists ";
}
}
function method3($filename){ //20sec
$h = fopen($filename, 'r');
if ($h !== false) {
echo 'File exists';
fclose($h);
}
}
function method5($url){ //21 sec
if(@file_get_contents($url,0,NULL,0,1)){
echo "image exists";
}
}
function method6($url){ //22 sec
if (false === file_get_contents($url,0,null,0,1)) {
echo "no ";
}
}
function method1($url){ //13 sec
exec("wget --spider -v ".$url);
}