I currently have a script that uses curl to check the file size of about 3000 images every time the a user visits the page.. this is because every time the content might change.
If it matches the size of 7442 bytes it changes the path of the image, if it doesn't it, maintains it's source.
The image URL is stored on $variable, mysql, and both remote and local xml file. But the image iself is always stored remotely.
$image = 'http://remoteserver.com/user22.jpg';
//Check if all thumbs are ok real and available
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
if($size == 7442){
echo '<img src="https://www.newdomain.com/tmp.jpg" height="190.11"/></a>';
} else {
echo '<img src="' . $image . '" alt="' . $user . '" /></a>';
}
When it's activated the page takes about 40 seconds to load, when it's commented out, it takes 3 seconds. But it gets executed every time any user visits the webpage or if I execute curl before adding data to mysql and change address in mysql,it causes a massive delay in loading that info onto that mysql and thus not showing all the images.
I know there's a lot depending on this check, both server response times, php config, and so on.. But I really need this image file check to work, and can't afford to have a 40 second load time every time a user visits the page.
Any suggestions/help? Thank you