PHP, symlinks, and the realpath cache

Annika Backstrom
in misc, on 6 May 2011. It is tagged #Programming, #performance, and #PHP.

I've had issues in the past where modifying symlinks seems to break my web apps: I change the symlink target, but PHP still loads the old target for seconds or minutes. Yesterday I realized this was happening because of the PHP realpath cache. This cache can be emptied using clearstatcache(), but the cache is maintained per-thread, so it's not a silver bullet. Only the active thread will have its cache cleared, where you may have dozens of threads in total (e.g. instances of php-fpm, or httpd children in prefork mode).

So, from now on I'll just consider symlinks harmful, I suppose.