-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset cache via terminal/command line #112
Comments
There is a way to do this as I've described on the SO thread. This is due to an architectural constraint of how OPcache works. Consider the multiple Vhosts example where your server is running dozens of separate UID hierarchies. Each UID would have its own cache -- which cache would your cli call connect to? This isn't an OPcache issue really in terms of current or road-mapped functionality, so can I suggest that you close this issue. Thanks. |
Thanks again for your response and help. Perhaps you can see this issue as a feature request for a simpler way to achieve this? |
Most accelerators bundle in some form of management GUI and IMO adding one to OPcache would be a good feature. Another SO Thread mentioned this one: PeeHaa/OpCacheGUI. |
We won't provide command line interface. It's possible to reset cache calling opcache_reset() from a PHP script accessed through HTTP. e.g. Put the following file into your web root. opcache_reset.phpthen call it using command: wget http://127.0.0.1/opcache_reset.php It's also a good idea to protect this file with password or limit it's usage to localhost only. |
@dstogov That's exactly what I did but feels like a workaround to me. But its ok for now. |
Do you have any reasonable explanation of not providing the commandline feature ? |
@czapeczek I agree - in fact, I created a page that just resets the cache - when my cache is having trouble (see my other open issues), this page crashes when I open it (because the cache is crashing), yet the cache is now cleared. We really need a way to clear this that is not tied to the webserver itself. |
The reasonable explanation is that the shared memory segment is anonymous and only accessible from the process that created it. There is no way to write a command line tool that can access it. Therefore, if you cache_reset web script fails, your only recourse is to restart your web server. |
Ok, well, I can see that, but do not agree that the current method is far from ideal? |
The alternatives are worse. If you do not make it an anonymous mmap segment then you have to worry about orphaned ipcs which you would manually have to clean up in order for the server to work at all. And I have never encountered the case where I couldn't run my admin script. |
I guess that depends on your definition of "working." :) My admin script will give me a 500 error when Opcache is failing for #127. It does reset the cache, but I can't tell (meaning, I just have to hope that it's working due to the 500 error.) |
Ah, Windows. Not my thing. Sorry. |
I am bothering with this because my deploy procedure is now
With the wget, my worrie is that everyone will be albe to clear the cache until I provide a token at least and i just don't like such solutions. Thanks for the feedback |
Normally the way you solve this is in the web server config. You restrict it to only allow access to that reset script from localhost and you make hitting that script part of whatever local deploy mechanism you run. You could also fix your deploy strategy to not need a cache reset, of course. eg. http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ |
@czapeczek, @laurin1, as Rasmus says, this isn't unsatisfactory. To me this is a bit like expecting the IP layer to include TCP support: here we have an architectural constraint that is simply addressed by adding an additional simple management tier. As to access control and preventing "everyone" being able to reset the cache then there are many standard ways of preventing this. One simple example is that your CLI script and the web script are both under your control and can therefore use a shared secret making it practically impossible for 3rd parties to compromise the system -- unless of course they have already compromised it to the extent that they can access your PHP source, in which case they've possibly got access to your databases, etc. Whatever you think this isn't an issue with OPcache as it's currently scoped and this issue should remain closed. At best this is an enhancement request which doesn't belong here. |
FYI: I was searching for a solution to call And I found a way of doing so using cgi-fcgi to directly comunicate with php-fpm without requiring a webserver to be involved. #!/bin/bash
echo '<?php opcache_reset(); echo "ok\n";' > /tmp/php-fpm-opcache-reset.php;
SCRIPT_FILENAME=/tmp/php-fpm-opcache-reset.php \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /var/run/php5-fpm.sock;
rm /tmp/php-fpm-opcache-reset.php; |
...just to iterate on the idea I have just created php-fpm-cli which allows stuff like: php-fpm-cli -r 'opcache_reset();' -connect /var/run/php5-fpm.sock
# or
php-fpm-cli -r 'var_dump(opcache_get_status());' -connect /var/run/php5-fpm.sock |
@muhqu : thanks for your solution, it's really helpful. because it's not only resolve the opcache clear issuse and also reslove how to do health check of php-fpm that without web server ! thanks again! |
@chrisLeeTW I'm also using it to monitor apcu metrics. works great so far. ;-) |
@muhqu php-fpm-cli is awesome and it also solve my several problem, thank you. |
|
@muhqu your script is awesome! Thank you. |
If you're using
This will gracefully restart Apache -- it should cause no disruption for connected users. |
@muhqu works like a charm!!! perfect for my continuous integration setup... |
@muhqu thanks ! Awesome script, works for me in my first try. |
For those who get the
error, you have to
|
…and for those on RHEL/CentOS:
|
Note that the following will all clear opcache:
The second and fourth options are gentle with connected users. More about the |
So does |
Please explain why graceful-stop + start is not a viable approach. It is made for such circumstances. |
OK, this is a personal view, but the 2.4 graceful stop / restart is a lot better than a normal stop in that it |
I don't see how there is a throughput collapse wiht |
I think that you are trying to describe the |
There should be a way to reset the cache for any php instances (CLI/FPM...) via the command line. Just running
php -r 'opcache_reset();'
doesn't work yetMore workarounds and discussion:
http://stackoverflow.com/questions/17716639/opcache-clean-cache-in-php5-4-and-lower/
The text was updated successfully, but these errors were encountered: