我试图在符号链接式部署后重置PHP opcache。我的项目中有opcache_reset.php
文件,在文档根的符号链接替换之后由wget
执行:
<?php
clearstatcache(true);
opcache_reset();
尽管如此,仍然使用旧文件。根据{{1}}输出,opcache_get_status()
增加的数量manual_restarts
保持最新,但文件路径仍然过时。我需要在部署后一分钟左右手动调用last_restart_time
以使事情正确。
PHP版本是5.5.6,ZendOpcache是7.0.3-dev。 Opcache配置:
opcache_reset.php
答案 0 :(得分:39)
ZendOptimizerPlus issue中描述的原因和两种可能的解决方案。
我们在nginx配置中使用$realpath_root
来解决它:
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
答案 1 :(得分:1)
如果由于某种原因,您无法在$realpath_root
中使用fastcgi_param并无法使用符号链接样式部署,请尝试在您的php ini配置中设置opcache.revalidate_path = On
。我找不到任何好的文档来解释这个ini目录的工作原理,但是在更改符号链接后它确实起作用了。希望这对任何人都有帮助。
答案 2 :(得分:0)
我也遇到了这个问题,最后我做出了解决方案。
$ curl -sO http://gordalina.github.io/cachetool/downloads/cachetool.phar
$ chmod +x cachetool.phar
您可以连接到自动猜测的fastcgi服务器(如果/var/run/php5-fpm.sock是文件或127.0.0.1:9000)
apc
apc:bin:dump Get a binary dump of files and user variables
apc:bin:load Load a binary dump into the APC file and user variables
apc:cache:clear Clears APC cache (user, system or all)
apc:cache:info Shows APC user & system cache information
apc:cache:info:file Shows APC file cache information
apc:key:delete Deletes an APC key
apc:key:exists Checks if an APC key exists
apc:key:fetch Shows the content of an APC key
apc:key:store Store an APC key with given value
apc:sma:info Show APC shared memory allocation information
opcache
opcache:configuration Get configuration information about the cache
opcache:reset Resets the contents of the opcode cache
opcache:status Show summary information about the opcode cache
opcache:status:scripts Show scripts in the opcode cache
示例:
[root@ip-172-31-5-244 ~]# php cachetool.phar opcache:status
+----------------------+---------------------------------+
| Name | Value |
+----------------------+---------------------------------+
| Enabled | Yes |
| Cache full | No |
| Restart pending | No |
| Restart in progress | No |
| Memory used | 42.71 MiB |
| Memory free | 85.29 MiB |
| Memory wasted (%) | 0 b (0%) |
| Strings buffer size | 8 MiB |
| Strings memory used | 5.31 MiB |
| Strings memory free | 2.69 MiB |
| Number of strings | 103847 |
+----------------------+---------------------------------+
| Cached scripts | 1261 |
| Cached keys | 2748 |
| Max cached keys | 7963 |
| Start time | Thu, 08 Feb 2018 02:28:56 +0000 |
| Last restart time | Thu, 08 Feb 2018 03:10:19 +0000 |
| Oom restarts | 0 |
| Hash restarts | 0 |
| Manual restarts | 1 |
| Hits | 47839 |
| Misses | 1269 |
| Blacklist misses (%) | 0 (0%) |
| Opcache hit rate | 97.415899649752 |
+----------------------+---------------------------------+
[root@ip-172-31-5-244 ~]#
[root@ip-172-31-5-244 ~]#
[root@ip-172-31-5-244 ~]# php cachetool.phar opcache:reset
[root@ip-172-31-5-244 ~]#
[root@ip-172-31-5-244 ~]#
[root@ip-172-31-5-244 ~]# php cachetool.phar opcache:status
+----------------------+---------------------------------+
| Name | Value |
+----------------------+---------------------------------+
| Enabled | Yes |
| Cache full | No |
| Restart pending | No |
| Restart in progress | No |
| Memory used | 10.43 MiB |
| Memory free | 117.57 MiB |
| Memory wasted (%) | 0 b (0%) |
| Strings buffer size | 8 MiB |
| Strings memory used | 545.69 KiB |
| Strings memory free | 7.47 MiB |
| Number of strings | 103847 |
+----------------------+---------------------------------+
| Cached scripts | 0 |
| Cached keys | 0 |
| Max cached keys | 7963 |
| Start time | Thu, 08 Feb 2018 02:28:56 +0000 |
| Last restart time | Thu, 08 Feb 2018 03:19:00 +0000 |
| Oom restarts | 0 |
| Hash restarts | 0 |
| Manual restarts | 2 |
| Hits | 0 |
| Misses | 2 |
| Blacklist misses (%) | 0 (0%) |
| Opcache hit rate | 0 |
+----------------------+---------------------------------+
您可以注意到内存,缓存键,每次点击都变为0 :-)。它非常有用。我也很容易将它与Ansible一起感兴趣。
它的apcu和其他东西的应用:在那里检查更多 http://gordalina.github.io/cachetool/