PHP Cache refresh without restarting Apache - php

A few of my sites seems to have server-side cache and I keep having to restart the httpd server every time I make changes to the PHP code
Is there a way not to restart Apache but have PHP code changes show up instantly?

7 years ago..
I'm not sure you would read this or not.
But I think what you want was changing opcache.enable option.
Go to php/etc/php.ini and try to change opcache.enable=0
But I think you'd better do that for development, not real services.

Related

Bitnami Wampstack: PHP caching requires server restart

I setup a WAMP stack for the first time using Bitnami. Got working pretty quickly with vhost and everything, running a couple WordPress websites for local development. The problem is, nearly everytime I save a change to a PHP file the changes don't appear when I refresh the browser unless I restart the Apache server.
I've searched around for a couple days now for a solution but nothing seems to work, considering going back to XAMPP for local development. I tried to disable opcache in the php.ini as someone suggested but that didn't work.
Any ideas what it could be?
In httpd.conf comment out:
# Include conf/pagespeed.conf
# Include conf/pagespeed_libraries.conf
In php.ini set:
opcache.enable=0
opcache.enable_cli=0
Source

Opcache clears too quickly

I have setup my website on a new hosting (virtual cloud), however I am looking at the opcache and the scripts not being used for say a minutes or so are removed from the cache.
So is there a way to stop it? or is it a normal behaviour?
Thanks a lot.
There is configuration for that actually.
opcache.revalidate_freq=2, the default value is 2 seconds, opcache will try to check for timestamps every 2 seconds and if the files are changed it will revalidate.
You can change the value to match your needs, or you can just turn timestamp check off using this conf opcache.validate_timestamps=0, but in this case each time you deploy code to production you have to restart php-fpm (if you are using php-fpm) and web server
opcache.revalidate_freq=2 or any integer value
opcache.validate_timestamps=1 or opcache.validate_timestamps=0
Sounds like you need to define validate_timestamps=0 in php.ini. Beware of this though - if you upload any changes to your PHP files you will need to restart either Apache (if you use mod_php5) or PHP5-FPM, or clear the opcache manually.
For details on how to clear the opcache manually you basically have to create a PHP file with opcache_reset() and run it, but this has to be in the same SAPI as your other files - i.e. run by PHP5-FPM if that is what is serving the rest of your files.
http://ihaveabackup.net/2013/10/19/invalidating-the-opcache-in-php-5-5/

disable php files caching for debugging

I have a vps with zpanel installed and apache2 - php - mysql.
I'm developing a small backend for a website in php, for sites ready to publish the situation is perfect, but now I need to disable the server feature that caches php files to test instantly the correct (last modified version) of my php files.
This is because while html and js files, when edited, are reloaded correctly immediately, with php I have a long wait before it updates or I have to restart the server.
I tried to open php.ini and look for "cache" and set to "1" millisecond almost all the values with no luck.
what could I try?
P.S. it's not a browser cache problem, that's a server side problem.
Solved: inside php.ini I added a line with
apc.enabled=0
after that I restarted apache2 and now php files are updated istantly as they should
thanks for the suggestion to look into phpinfo

do we need to restart apache + APC after new version deployment of app?

when we deploy our app, we simply create a new folder and point a symbolic link to it, so apache will always find its way to the latest build.
However, we get strange errors when we deploy and continue testing without first rebooting the apache server. We also have APC running and have a feeling that caching has something to do with this.
Is it normal that an apache restart is required when deploying a new version of our php application when APC is active? Or is there a better way, e.g. clearing the APC cache using a shell script?
You can use apc_clear_cache().
See related questions:
How to clear APC cache entries?
How to clear APC cache without crashing Apache?
depends if you have the apc.stat setting in php.ini On or Off. If Off (typical for a production site) then you need to clear the code cache or restart apache; if On, then it should pick up the new code automatically
Normally, APC will 'stat' each PHP file to see if it has been changed since it was last cached. So restarting Apache is not required for all application upgrades.
BUT if your application uses apc_store() to store application data in the cache and some of that data might change after an upgrade, then restarting Apache is an easy way to flush the entire APC cache.
I believe apache2ctl graceful would work, too.
Also, APC performs a little better if you turn off the 'stat' checking; so if you disable that feature, then you'll want to restart Apache anyway.

How do you use gettext on server (Apache) you can’t restart?

I asked this question on serverfault but I didn't get any response. I try here...
I developped a site on my web server at home.
When I modify the translation files, I have to restart the web server Apache.
/etc/init.d/httpd graceful
Easy...
Suppose that my site is hosted on shared host.
Suppose now I need to modify the translation files.
I can't restart the server...
How do you use gettext in this context?
Are you allow to restart the server with the option graceful only?
Does the share host restart the server once a day to resolve this kind of problem?
How do you work with such constraints?
call clearstatcache();
after making translation from *.po to *.mo
the post here on the gettext function has some information for making gettext work without restarting apache:
http://www.php.net/manual/en/function.gettext.php#58310
You can rename your *.mo file and your gettext domain to flush gettext cache without restarting apache server.But in production environment,it's unsuitable.
There is no other solution than to brutally force a cache miss for each and every *.mo file every time one of them changes. Change a single string? New cache era!
I do this by writing middleware that copies all *.mo files to a timestamp-named directory (the timestamp being that of the newest *.mo file) and updates the application config with the new message path - if the newest timestamp actually changed, that is. Thus textdomains are now loaded from completely different paths, and this is what finally manages to kill the stupid gettext cache stinking dead.

Categories