gpt4 book ai didi

php - APC 已启用但 Apache 仍在打开文件?

转载 作者:可可西里 更新时间:2023-11-01 13:59:10 26 4
gpt4 key购买 nike

我在一个高流量的网络服务器场工作,该服务器场提供动态 PHP 代码,其中包含大多数请求的大约 100 个文件。启用了 APC 操作码缓存,启用了 include_once_override,并且我已经为缓存分配了 64MB 内存,但是当我跟踪一个 apache 进程时,我仍然看到它打开()和统计()所有这些包括每个请求应该是从缓存中拉出。我可以在缓存统计信息中看到缓存正在被填充并以 100% 的命中率使用。谁能提供任何见解?

最佳答案

Will,请确保您对应用程序中的每个包含项都使用了完整路径名。根据 APC 文档:

apc.stat integer

Be careful changing this setting. This defaults to on, forcing APC to stat (check) the script on each request to determine if it has been modified. If it has been modified it will recompile and cache the new version. If this setting is off, APC will not check, which usually means that to force APC to recheck files, the web server will have to be restarted or the cache will have to be manually cleared. Note that FastCGI web server configurations may not clear the cache on restart. On a production server where the script files rarely change, a significant performance boost can be achieved by disabled stats.

For included/required files this option applies as well, but note that for relative path includes (any path that doesn't start with / on Unix) APC has to check in order to uniquely identify the file. If you use absolute path includes APC can skip the stat and use that absolute path as the unique identifier for the file.

PHP 的一个好的经验法则是定义一个包含项目完整路径的常量,如下所示:

// Assumes __FILE__ is in the root of your project
define('PATH_PROJECT', realpath(dirname(__FILE__)));

然后像这样使用你的包含:

include_once PATH_PROJECT . '/some/dir/file.php';

因此您仍然可以方便地使用相对路径,但实际上是在使用完整路径。

关于php - APC 已启用但 Apache 仍在打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1184131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com