Forum Moderators: coopster
Currently, the images are dynamically generated by a simple PHP script (using PHP functions: imagecreate, imagecolorallocate, imagettftext, imagegif). It uses/includes a (200 KB) TTF font file to create the text on every request.
I'm thinking of saving static images, recreated every time users make a change (not so often), so that the many image requests are not processed by a PHP script, but lead to static images (saved as GIF image files on the server).
My question is: does the last option use much less server resources?
Will the PHP script use a lot of memory, if requested every few seconds?
Thanks in advance for your insights and experiences!
Arno
Check if the file "cache/<user>.gif" (or whatever) exists
if it exists,
send it to the client
Otherwise
generate the image
send it to the user
save it to "cache/<user>.gif"
this would give you the advantage of only generating the ones that are required and would spread out the generation to when they are needed rather than doing them all at once, but of course isn't as fast as sending the static files directly but it shouldn't have much of an impact considering your server is currently handling generating the images every time :)
if the users are updating the details then you might also need to compare the date/time of the last change with the date/time of the cached image as well and re-generate when required (or simply have the page that updates their details delete the cached image)
although with that many users it would take a lot of storage space to save all of the images so if they aren't all used all of the time then it might make sense to have a script run every few days to clean up the ones that are rarely used just to save clogging up the disk space - assuming you dont have loads of free space to use up
I think the generate and cache solution is probably best - that's what Coppermine does, for example, and the initial generation sucks up CPU time. That's in the case of photos, though. Little CAPTCHA style images like you're talking about would be less of a problem obviously.
I am switching to static files now, it's indeed a better idea, certainly now I'm expecting many more users soon. The images aren't changed very often, but they are loaded frequently.
The script also gives a small delay compared to showing static files.
As for the size of the images: they're very small, containing only an email address, so always below 1 KB (normally 400-500 bytes).
Best regards.
SN
So all data are stored in a database, and images can be (re)generated by users through a secure personal settings page.
Is it useful to create more folders, to limit the number of images per folder? I mean is that any faster, if images are already ordered by ID there (naming: see above)?