Override opcache only after git push

I am using PHP with OPcache. I only git-push to master the deployment of my website during production (not really, it's right after unit tests, but it doesn't matter). In the file php.ini, OPcache parameters are “time” and “frequency”. But I just want to reset cache after git pull my server out.

So, I just need to call opcache_resetafter git-pull on my working server and set opcache.validate_timestampsto 0(never reset cache)

I have not read anything about this, so I doubt it: I do not know if this is a good practice. Did I miss something? Is there a risk or is everything okay?

Thank you so much!

PS: I use the PHP framework and composer ( composer installworks right after git-pull)

+4
source share
1 answer

To get the most out of OPCache, you should disable it opcache.validate_timestamps. If you subsequently call opcache_reset()from the script each time you deploy your code on the server, your OPCache is flushed once for each new set of files, and the system does not waste resources constantly checking files.

There are a couple of "gotchas" there:

First of all, make sure that the call opcache_reset()occurs, otherwise you will run the old code. If you have a script to perform the deployment, make sure that it does not work out loud if this step is not performed.

-, , PHP (mod_php vs php-fpm), opcache_reset() , . , PHP, ,

<?php

if (php_sapi() != "cli") die("Not accessible from web");
opcache_clear();

. PHP , , , -.

, script curl wget. , curl http://example.com/clear_cache.php?secret=abc123. script , , , - , .

, , , , , .zip , , , , git pull . , git pull && composer update . , , , , .

+1

All Articles