After going through phpThumb caching hell (lots of cached files in a dir, server freezing etc) I came up with this lib. When a user requests some content (say a resized image) an apache errordocument calls the lib which generates the content. The second time the same content get requested, apache will serve it directly without involving php or anything!