Detecting missing pictures

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
hessodreamy
Forum Commoner
Posts: 58
Joined: Wed Apr 20, 2005 8:11 am

Detecting missing pictures

Post by hessodreamy »

To avoid missing pictures on my site, and show a 'missing picture' image instead, I have been running a periodic file_exists check, and updating a flag in the database to show whether the picture exists or not.

But now I can't see any reason not to use file_exists on the fly. How fast is it? Would it slow down page load?

btw there's maybe 50,000 files in the image folder, if that makes any difference.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

This is realy hard to tell. If the database has it's own super fast server then maybe the database solution would be faster... But I doubt it, chances are that checking this on the fly is faster. Just test it and see what you get.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try it, find out.

As for having that many files in a single folder... generally not the best of ideas as many file systems don't like having multiple thousands of files in a single directory. They often won't deny you to do it, but performance in that directory will often degrade as more files are added. I'd suggest breaking the directory up into multiple directories.
hessodreamy
Forum Commoner
Posts: 58
Joined: Wed Apr 20, 2005 8:11 am

Post by hessodreamy »

hmmm... separating the files had occurred to me, but more for my own benefit rather than server performance. But yeah I do think that would be a good idea.

As for the original problem, if the difference isn't going to be significant, I think I'll go with checking them on the fly, just because the code, and the updating processes would be simpler.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Man... I've just beat feyd :D

Edit: Now I'm a real DevNetwork-er 8)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

If the images are off site the file_exists will be very slow.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Detecting missing pictures

Post by Oren »

bokehman:
hessodreamy wrote:To avoid missing pictures on my site
hessodreamy
Forum Commoner
Posts: 58
Joined: Wed Apr 20, 2005 8:11 am

Post by hessodreamy »

yeah!
Post Reply