views:

44

answers:

2

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.

  1. Have a symbolic link, for example /live, that is always the document root but is changed to point from one version to the next.
  2. Similarly, have a directory /live that is always the document root, but use

    mv live oldversion && mv newversion live

    to switch to new version.

  3. 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?

+1  A: 

Then after the switch, remove the old cache entries for files from release 1234.

You can only clear the entire cache or none at all. It's not a selective process. This may change your approach to the problem. If precompilation is paramount you may be forced to bring down the server during the switchover.

webbiedave
Ah, good to know. I just assumed it could be selective because of the way the user cache works.
Ben
+1  A: 

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.

Techpriester
Why do this? I am interested in the 100% solution: no downtime, no performance hit, no risk of weirdness for those exactly wrongly timed hits, and wanted to know if anyone had done this. Thanks for the ideas!
Ben
If you have two servers, you could install the newer version on one of them and then switch between the two. That would reduce your downtime to virtually 0. But forcing the opcode cache to cache everything right away, is just not worth any effort.
Techpriester
Okay, I accept that. I also wasn't aware of the apc.write_lock setting/feature, which eliminates most of my concerns.
Ben