Does anyone have a great system, or any ideas, for doing as the title says?
I want to switch production version of web app– written in PHP and served by Apache– from release 1234 to release 1235, but before that happens, have all files already in the opcode cache (APC). Then after the switch, remove the old cache entries for files from release 1234.
As far as I can think of there are three easy ways of atomically switching from one version to the next.
- Have a symbolic link, for example /live, that is always the document root but is changed to point from one version to the next.
-
Similarly, have a directory /live that is always the document root, but use
mv live oldversion && mv newversion live
to switch to new version.
- Edit apache configuration to change the document root to newversion, then restart apache.
I think it is preferable not to have to do 3, but I can’t think of anyway to precompile all php files AND use 1 or 2 to switch release.
So can someone either convince me its okay to rely on option 3, or tell me how to work with 1 or 2, or reveal some other option I am not thinking of?
Exactly why do you want to do this?
When I switch to a new release, I just stop my Apache, replace the PHP files on the server via checkout from my VCS and restart Apache. It mostly takes less than 30 seconds to pull this off, it’s even scriptable. All that is executed at a time when there are few or no users. After that, the opcode cache is empty and will fill itself as soon as someone uses the files.
Maybe the first few hits will not have optimal performance but that should not be so bad. On my production systems no one ever noticed this short performance drop. And there are some really heavy load systems among them.
You can even place a simple “upgrading … be back soon” screen on your server while replacing the files to avoid any disturbing error messages to your users.