PHP操作缓存重置+;符号链接式部署

PHP操作缓存重置+;符号链接式部署,php,deployment,symlink,opcache,Php,Deployment,Symlink,Opcache,我正在尝试在symlink样式的部署之后重置PHP opcache。在我的项目中有一个opcache\u reset.php文件,该文件在文档根的符号链接替换后由wget执行: <?php clearstatcache(true); opcache_reset(); 中描述的原因和两种可能的解决方案。 我们通过在nginx配置中使用$realpath\u root解决了这个问题: fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_s

我正在尝试在symlink样式的部署之后重置PHP opcache。在我的项目中有一个
opcache\u reset.php
文件,该文件在文档根的符号链接替换后由
wget
执行:

<?php
clearstatcache(true);
opcache_reset();

中描述的原因和两种可能的解决方案。 我们通过在nginx配置中使用
$realpath\u root
解决了这个问题:

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

我也遇到了这个问题,然后我终于找到了解决办法

$ 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)

例如:

    [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                               |
+----------------------+---------------------------------+
您可以注意到内存、缓存键、命中率everythings变为0:-)。它非常有用。我也很容易地把它和Ansible结合起来

它对apcu和其他东西的应用:在那里查看更多

如果由于某种原因无法将fastcgi_参数与
$realpath_root
一起使用并使用符号链接式部署,请尝试在php ini配置中设置
opcache.revalidate_path=On
。我找不到任何好的文档来解释这个ini目录在引擎盖下是如何工作的,但是在我更改了符号链接之后它确实工作了。希望这对任何人都有帮助。

我使用的是相同的NGINX指令。但是,我需要重新加载php fpm,以确保php fpm使用新目录中的代码。重新加载fpm会使我丢失一些请求。如果我不重新加载fpm,那么它仍然在旧目录中执行代码。同样的问题在这里描述:你能帮忙吗?好的!我在Nginx配置中使用它,如下所示
fastcgi\u param PHP\u VALUE opcache.revalidate\u path=“1”
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                               |
+----------------------+---------------------------------+