Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clearstatcache + include_path + sessions

Tags:

php

caching

Im having a problem where we run an upgrade for our web application.

After the upgrade script completes and access the web app via the browser, we get file not found errors on require_once() because we shifted some files around and PHP still has the old directory structure cached.

If we have the default 120 seconds for the realpath_cache_ttl to expire, then everything resolves itself, but this is not acceptable for obvious reasons.

So I tried using clearstatcache with limited success. I created a separate file (clearstatcache.php) that only calls this function (this is a one line file), and placed a call to it in our install script via curl:

<?php
clearstatcache(true);

This does not seem to work, however if I call this file via the browser it immediately begins to work.

I'm running PHP version 5.3

I started looking at the request header differences between my browser and curl, and the only thing I can see that might matter is the PHPSESSID cookie.

So my question is, does the current PHPSESSID matter (I don't think it should). Am I doing something wrong with my curl script? I am using

curl -L http://localhost/clearstatcache.php

EDIT: Upon further research, I've decided this probably has something to do with multiple apache processes running. clearstatcache will only clear the cache of the current apache process - when the browser is making a request a different apache process serves the request, and this process still has the old cache.

like image 454
14 revs, 12 users 16% Avatar asked Feb 12 '12 18:02

14 revs, 12 users 16%


People also ask

Do PHP files get cached?

A cache is a collection of duplicate data, where the original data is expensive to fetch or compute (usually in terms of access time) relative to the cache. In PHP, caching is used to minimize page generation time.


1 Answers

Given that the cache is part of the Apache child process thanks to mod_php, your solution here is probably going to be restarting the Apache server.

If you were using FastCGI (under Apache or another web server), the solution would probably be restarting whatever process manager you were using.

This step should probably become part of your standard rollout plan. Keep in mind that there may be other caches that you might also need to clear.

like image 148
Charles Avatar answered Sep 30 '22 07:09

Charles