Is getimagesize efficient??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rupam_jaiswal
Forum Newbie
Posts: 22
Joined: Thu Jun 05, 2008 12:54 am

Is getimagesize efficient??

Post 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
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Is getimagesize efficient??

Post 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".
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Is getimagesize efficient??

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Is getimagesize efficient??

Post by pickle »

Simplest might be to use file_exists()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Is getimagesize efficient??

Post by Apollo »

pickle wrote:Simplest might be to use file_exists()
Yeah but does that work on URLs too? (TS mentioned remote files)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Is getimagesize efficient??

Post by pickle »

It does if URL wrappers are on - and I think by default they are.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply