mabog Posted March 28, 2010 Share Posted March 28, 2010 What is the fastest way to check if external file (image) exists? I have tried these, but both are quite slow. if (@fclose(@fopen("http://www.example.com/image.jpg", "r"))) { if (@GetImageSize("http://www.example.com/image.jpg")) { In my page, there is 10 small external images. fopen took 15 sec to check and getimagesize 16.5 sec. Link to comment https://forums.phpfreaks.com/topic/196772-fastest-way-to-check-if-external-file-exists/ Share on other sites More sharing options...
mabog Posted March 28, 2010 Author Share Posted March 28, 2010 7.5 sec function checkRemoteFile($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); // don't download content curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if(curl_exec($ch)!==FALSE) { return true; } else { return false; } } http://hungred.com/how-to/php-check-remote-email-url-image-link-exist/ Link to comment https://forums.phpfreaks.com/topic/196772-fastest-way-to-check-if-external-file-exists/#findComment-1033007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.