我在mysql数据库中有850个youtube视频的列表。我需要检查它们是否仍然存在。如果不存在,它将更新数据库。我的代码适用于小型输入(例如20个视频),但对于850个输入,它会占用过多的内存并导致500 Internal Server Error。有没有办法将这项工作分成小部分,或者是否有可能检查视频是否存在?
$SQL = "SELECT * FROM tbl_channels WHERE status = 1";
$result = mysqli_query($mysqli,$SQL)or die(mysqli_error());
$body = "";
$i = 0;
while($row = mysqli_fetch_assoc($result)){
$channel_url = $row['channel_url_ios'];
$youtube_id = substr($channel_url, strpos($channel_url, "=")+1);
$youtube_id." = ";
$image_url = "https://img.youtube.com/vi/".$youtube_id."/0.jpg";
//echo $image_url;
$size = getimagesize($image_url);
if(!$size){
echo "image_not_found"."\n"."<br>";
Update('tbl_channels', array('status'=> 0), 'id='.$row['id'].'' );
$i++;
$body.=$i."- ".$row['channel_title']."\n";
//Delete('tbl_channels','id='.$row['id'].'');
}else{
echo "image found \n"."<br>";
}
}