Let’s see how to clear PHP OPcache without restarting PHP-FPM in this article. At Bobcares, with our Server Management Services, we can handle your server issues.
How to clear PHP OPcache without restarting PHP-FPM?
We can now easily clear the PHP Opcache without restarting PHP-FPM with the help of CacheTool. In this article, we will provide the instructions to install the CacheTool alongside a demonstration PHP-FPM Docker container.
Installing CacheTool
- Firstly, we need to create and Run a PHP-FPM App.
- Then install the CacheTool.
- Basic Operation resets the contents of the opcode cache.
- Lastly, confirm OPcache is empty.
Create And Run A PHP-FPM App
On the CLI, run the following command:
$ docker run \
--detach \
--name php56 \
--publish 8888:80 \
jdeathe/centos-ssh-apache-php:2.1.1
Copy Code
Now to verify that it functions.
$ curl -I http://localhost:8888/
Copy Code
In order to create some cache usage, make another request. We can also try a different URL.
$ curl -I http://localhost:8888/_phpinfo.php
Copy Code
Install The CacheTool
The
open_basedir
Copy Code
directive in the demonstration app restricts PHP files to the /var/www/app
Copy Code
directory, thus the CacheTool should be installed to /var/www/app/bin
Copy Code
with the proper permissions.
$ docker exec -i php56 curl -s \
-o /var/www/app/bin/cachetool.phar \
http://gordalina.github.io/cachetool/downloads/cachetool.phar
$ docker exec -i php56 chmod 750 /var/www/app/bin/cachetool.phar
$ docker exec -i php56 chown app:app /var/www/app/bin/cachetool.phar
Copy Code
Basic Operation
With the following code, we can clear the contents of the opcode cache without restarting PHP-FPM.
$ docker exec -i php56 \
php /var/www/app/bin/cachetool.phar \
--tmp-dir=/var/www/app/var/tmp \
--fcgi=/var/run/php-fpm/app-www.sock \
opcache:reset
Copy Code
Verify OPcache Is Empty
We have to include the command in the composer post install/update scripts to ensure that the OPcache is cleared after each deployment without restarting PHP-FPM. In this manner, OPcache will also update its cache each time we install the dependencies:
"post-install-cmd": [
// ...
"cachetool opcache:reset --fcgi=/var/run/php5-fpm.sock"
]
Copy Code
Identify Usage
In order to explore the CacheTool usage, use the following code:
$ docker exec -i php56 \
php /var/www/app/bin/cachetool.phar help
Copy Code
Other OPcache Commands
1.
opcache:configuration
Copy Code
: Access the cache’s configuration data.
2.
opcache:invalidate:scripts
Copy Code
: Clear the scripts in the opcode cache.
3.
opcache:reset
Copy Code
: Resets the opcode cache’s contents.
4.
opcache:status
Copy Code
: Display a summary of the opcode cache’s information.
5.
opcache:status:scripts
Copy Code
: Display opcode cache’s scripts.
[Need assistance with another issue? We’re here to help.]
Conclusion
In this article, we have included the steps from our Support team to install PHP CacheTool, along with the code to find its usage and also available commands with the Opcache.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments