PHP or Apache seems to be caching files read via file_get_contents or include (unwanted behaviour)
Asked Answered
H

1

3

Our web application has version numbers that get served out to the client on each request so we can detect an update to the code (ie rolling updates) and displays a popup informing them to reload to take advantage of the latest update.

But I'm experiencing some weird behaviour after the update of the version number on the server, where some requests return the new version number and some return the old, so the popup keeps poping up until you have reloaded the page a few times.

Originally I suspected maybe apache was caching files it read off disk via file_get_contents so instead of storing the version number in a plain text file, I now store it in a php file that gets included with each request, but I'm experiencing the exact same issue!

Anyone have any ideas what might be causing apache or php it self to be serving out old information after i have done an update?

EDIT: I have confirmed its not browser caching as I can have the client generate unique urls to the server (that it can deal with via rewrite) and i still see the same issue where some requests return the old version number and some the new, and clearing the browser cache doesn't help

EDIT 2: The response headers as requested

HTTP/1.1 200 OK
Date: Mon, 23 Jul 2012 16:50:53 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.7
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 500
Connection: close
Content-Type: text/html

EDIT 3: So trying to reproduce to get the response headers I found I could only make it happen going through our full deploy process which involves creating versioned folders storing the code and symlinking the relavant folder into the webroot. Just changing the version number wasn't enough to cause it to happen! So seems to be somehow related to the symlinks i create!

Houser answered 23/7, 2012 at 16:16 Comment(4)
Are you absolutely, positively, 100% sure that it's not a browser caching issue?Eternize
@Crontab - see update to question! cheersHouser
Post the HTTP response headers.Fringe
I'm thinking maybe a graceful restart of apache after deploying the code may be in order, but would rather not have to restart apacheHouser
L
2

I have the same problem when there is a change in the symlink. Have a look at https://bugs.php.net/bug.php?id=36555 it's maybe what you are looking for.

Try (as said in this bug report) setting realpath_cache_size is 0.

Larena answered 7/9, 2012 at 16:5 Comment(1)
Just had this exact same issue, and your solution solved it. In this case the problem was a .env file that was being symlinked in returning the wrong contents. Thanks!Aton

© 2022 - 2024 — McMap. All rights reserved.