PHP, symlinks, and the realpath cache

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.

2 Comments

  1. [...] sometimes? At this point, Ceeram of #cakephp on Freenode helped me out by pointing me at this blog: PHP, symlinks, and the realpath cache, which explained perfectly what was going [...]

  2. Utoxin says:

    Thanks for this posting! It helped me resolve a problem I’ve been hunting down for over two weeks. You’re mentioned here: CakePHP + Symlinks = Pain

Leave a Comment

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>