Page 1 of 1

Is getimagesize efficient??

Posted: Fri Jul 09, 2010 1:45 am
by rupam_jaiswal
HI,
Please excuse if similar issue has been posted earlier.

I want to check if a remote image exists or not.
say if url is http://example/image.png
and no image exists there, then...??

Earlier I was using @getimagesize function, but later on found this comment saying that it makes server slow for on large images.

http://www.php.net/manual/en/function.g ... .php#88793

I don't know if the solution mentioned in that comment is correct rather efficient?

Is there any other efficient, fast, small solution for this?

Thanks in advance...
Regards

Re: Is getimagesize efficient??

Posted: Fri Jul 09, 2010 3:11 am
by Apollo
I'd say just open a socket and instead of actually downloading the image file, just download the header and see if you get a "200 OK" response. Optionally also follow 301/302 redirects, depending on whether this meets your definition of "exists".

Re: Is getimagesize efficient??

Posted: Fri Jul 09, 2010 4:44 am
by John Cartwright
Apollo wrote:I'd say just open a socket and instead of actually downloading the image file, just download the header and see if you get a "200 OK" response. Optionally also follow 301/302 redirects, depending on whether this meets your definition of "exists".
I prefer cURL with the CURLOPT_NOBODY option. No need to mess with HTTP protocols.

Re: Is getimagesize efficient??

Posted: Fri Jul 09, 2010 10:30 am
by pickle
Simplest might be to use file_exists()

Re: Is getimagesize efficient??

Posted: Fri Jul 09, 2010 10:34 am
by Apollo
pickle wrote:Simplest might be to use file_exists()
Yeah but does that work on URLs too? (TS mentioned remote files)

Re: Is getimagesize efficient??

Posted: Fri Jul 09, 2010 10:43 am
by pickle
It does if URL wrappers are on - and I think by default they are.