Jump to content

fastest way to check if external file exists


mabog

Recommended Posts

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.

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/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.