PDA

View Full Version : Is getimagesize efficient??



php_techy
07-09-2010, 06:44 AM
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.getimagesize.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

djr33
07-09-2010, 01:49 PM
No, not really. Anything with images will be somewhat inefficient. You could instead just verify that the file exists and has a valid extension for images like .jpg but that won't guarantee the file is valid. It would work in most cases though.

traq
07-09-2010, 02:41 PM
The @ is inefficient. You should suppress errors via your php.ini instead.

djr33
07-09-2010, 08:15 PM
True, but that will suppress all errors: for this sort of test, sometimes you must suppress that to avoid a warning if it fails.

Also, the efficiency lost from the @ compared to the time it takes to process getimagesize() would be insignificant.