[php]Generating images, or storing them?

Joined
Apr 29, 2005
Messages
6,400
Reaction score
130
On my latest project (http://pie-designs.net/piegebra) I put mathematical equations into images. Currently, I have it so that the equation is stored in a database along with an id and some other info. Meaning that every time someone visits the image it needs to be created first. I have no idea if this the best way to do it.

So, I was wondering what would be the best to do something like this? Should I store the images on my web server and have no need for a mysql database? Or should I keep it this way and use minimum storage space?
 
Do both, generating the images on the fly and saving them, by using a cache system. If an image is being accessed frequently, then it should remain cached for a long time, whereas an image being accessed rarely, or maybe only once, need not be cached at all. The more the image is accessed, should mean the longer the image remains cached. Which means, that if the image should eventually stopped being accessed, it would be deleted after a period of time of inactivity. This results in the saving of space, because only the frequently requested images are saved, and less overhead because you aren't constantly creating the images that are frequently requested.
 
Question is, are you or do you expect to be in lack of either processing power or diskspace in the foreseeable future?

Your way is quite inefficient and what King Izu suggested is far better, but it also means a lot of coding for a problem that might not even exist.

In my experience cache is almost always better than generating - you can very easily add another few hundred gigabytes of disk space to a webserver cluster, but increasing processing power is an extremely hard and expensive matter :)
 
I kind of like King Izu's idea.

I was thinking of something like a visits a day system. Where if an image has a certain amount of visits a day it gets cached. And then a weekly cron job to cache/uncache images.

Though, one image is only around 0,5 kb so as FF already said, I think it's a bit too much coding for a non-existing problem.

I think I'm going to keep my system, at least till I work out all the bugs so any faulty generated images won't be saved.
 
Back