Filesystem Caching without Cruft in PHP
In PHP on a Unix system, you can
unlink() files after
/tmp free of cruft. I'm currently using this in a file caching
setup, where the cache exists only for the lifetime of the request.
The file is unlinked as the last step, removing it from
/tmp, but it's
still available for
fread() through the cached file
pointer (in a static, singleton, or other non-persistent store of
choice). When the request ends, the pointer is closed, and the
filesystem will free the space used by that file.
No keeping track of files for cleanup, no registering a shutdown function, and we don't have to retain the file contents in memory.