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

发布于 2024-07-29 06:57:49 字数 249 浏览 10 评论 0原文

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

I'm working on a high-traffic webserver farm serving dynamic PHP code which includes around 100 files on most requests. APC opcode cache is enabled, include_once_override is enabled, and I have allocated 64MB ram to the cache, yet when I strace an apache process I still see it open()ing and stat()ing all of these includes for every request which should be pulled from cache. I can see in cache stats that the cache is being populated and used with a 100% hitrate. Can anyone offer any insight?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢好甜 2024-08-05 06:57:49

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

apc.stat 整数

更改此设置时请小心。 该选项默认为打开,强制 APC 对每个请求统计(检查)脚本以确定其是否已被修改。 如果已修改,它将重新编译并缓存新版本。 如果关闭此设置,APC 将不会检查,这通常意味着要强制 APC 重新检查文件,必须重新启动 Web 服务器或必须手动清除缓存。 请注意,FastCGI Web 服务器配置可能不会在重新启动时清除缓存。 在脚本文件很少更改的生产服务器上,通过禁用统计信息可以显着提高性能。

对于包含/必需的文件,此选项也适用,但请注意,对于相对路径包含(Unix 上不以 / 开头的任何路径),APC 必须进行检查才能唯一标识该文件。 如果您使用包含 APC 的绝对路径,则可以跳过统计并使用该绝对路径作为文件的唯一标识符。

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

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

然后像这样使用包含:

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

因此,您仍然可以享受相对路径的便利,但实际上正在使用完整路径。

Will, be sure you are using full pathnames to every include in your application. Per the APC documentation:

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.

A good rule of thumb for PHP is to define a constant that contains the full path to your project like so:

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

then use your includes like so:

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

Thus you still have the convenience of relative paths, but are really using full paths.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文