【问题标题】:PHP opcache reset + symlink-style deploymentPHP opcache 重置 + 符号链接式部署
【发布时间】:2014-07-07 09:45:06
【问题描述】:

我正在尝试在符号链接样式部署后重置 PHP opcache。我的项目中有opcache_reset.php 文件,在文档根目录的符号链接替换后由wget 执行:

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

尽管如此,旧文件仍被使用。根据opcache_get_status() 的输出,manual_restarts 的数量增加,last_restart_time 保持最新,但文件路径仍然过时。我需要在部署后一分钟左右手动调用opcache_reset.php 以使事情正确。

PHP 版本是 5.5.6,ZendOpcache 是 7.0.3-dev。 Opcache 配置:

opcache.blacklist_filename => no value
opcache.consistency_checks => 0
opcache.dups_fix => Off
opcache.enable => On
opcache.enable_cli => On
opcache.enable_file_override => Off
opcache.error_log => no value
opcache.fast_shutdown => 1
opcache.force_restart_timeout => 180
opcache.inherited_hack => On
opcache.interned_strings_buffer => 8
opcache.load_comments => 1
opcache.log_verbosity_level => 1
opcache.max_accelerated_files => 4000
opcache.max_file_size => 0
opcache.max_wasted_percentage => 5
opcache.memory_consumption => 128
opcache.optimization_level => 0xFFFFFFFF
opcache.preferred_memory_model => no value
opcache.protect_memory => 0
opcache.restrict_api => no value
opcache.revalidate_freq => 60
opcache.revalidate_path => Off
opcache.save_comments => 1
opcache.use_cwd => On
opcache.validate_timestamps => On

【问题讨论】:

    标签: php deployment symlink opcache


    【解决方案1】:

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

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

    【讨论】:

    • 我正在使用相同的 NGINX 指令。但是,我需要重新加载 php fpm 以确保 php fpm 使用新目录中的代码。重新加载 fpm 让我失去了一些请求。如果我不重新加载 fpm,那么它仍然会执行旧目录中的代码。此处描述的相同问题:serverfault.com/questions/630573/…您能帮忙吗?
    【解决方案2】:

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

    【讨论】:

    • 好收获!我在我的 Nginx conf 中使用它fastcgi_param PHP_VALUE opcache.revalidate_path="1";
    【解决方案3】:

    我也遇到过这个问题,最后我找到了解决方案。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2019-09-29
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      相关资源
      最近更新 更多