如何处理多余的内存使用? 我的代码导致“500内部服务器错误”!

I have a list of 850 youtube videos in mysql database. I need to check wheter they still exists or not. If it doesn't exists it updates the database. My codes work for small inputs like 20 videos but with 850 inputs it uses excess memory and causes 500 Internal Server Error. Is there any way to this work into small parts or are there any possible way check wether the videos exists or not?

$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"."
"."<br>";
        Update('tbl_channels', array('status'=> 0), 'id='.$row['id'].'' );
        $i++;
        $body.=$i."- ".$row['channel_title']."
";

        //Delete('tbl_channels','id='.$row['id'].'');

    }else{
        echo "image found 
"."<br>";
    }
}