I have a web application build on PHP that (does some processing and) displays images hosted on external servers. Some of these images (i.e. from Flickr) when they are deleted, leave a redirect behind that points to a “Missing Image” gif or something equivalent.
By using the get_headers() function in php on each image, I was able to check server-side if an image was deleted or not (for example, by checking if the Content-Type was image/gif instead of image/jpg, on Flickr images).
The problem is that each page returns 20-100 images on average (sometimes even more), and get_headers() requires on average 0.3-0.5s for each image, thus making the wait time for the user too long.
I was wondering if this check could be done client-side, using javascript. The user will be waiting for the images to load (as with any page), I will be checking the images if they are valid, and set display property to none on the missing ones.
You can use
curl_multi_exec()to check multiple URLs at once. If you use the following cURL options:…this will prevent the following of redirects. You can then use this information (whether the response is a redirect or not, see
CURLINFO_HTTP_CODEincurl_get_info()) to determine whether the file exists. By usingcurl_multi_exec()you will perform multiple checks at once, which should drastically reduce the page load time.