I have a project in which a user uploads an image through a form and the server does some thumbnails. The thumbnail making process is very slow so I thought that doing the i
On one system, I've seen an independent background process making the thumbnails:
thumbnails
table, linking the original image and the new unique name, marked as "to be thumbnailed"There's an independent background process (and its watchdog), which continuously watches that special folder (most OSes have various tools that notify you when a folder's contents change); if it finds an image there, it will:
When you need the thumbnail, check the thumbnails
table - if the image is not "thumbnailed OK", show a placeholder, else get the correct thumbnail name and display this.
That worked great - most thumbnails were created within a few seconds, without slowing down the user-facing scripts. Note that you'll need to start the background script somehow - in this case, there was a watchdog in cron, which restarted the thumbnailing script if it died.
@yankee objects that some elements are uncommon:
Edit: I checked the site, and there is one more mechanism - this one is not necessary and adds a bit of load, but looks cool, especially if you don't expect full page loads very often (e.g. on AJAX-driven sites):
img
with class="nothumb"
This loads the thumbnails as soon as they are ready, at the cost of some resources. For a continuous background process, it's not really needed; but if you want to ensure that users will see the thumbnails as they become available instead of on their next pageload, this is an useful addition.