APC不缓存文件,但缓存用户数据

发布于 2024-10-28 09:08:19 字数 689 浏览 3 评论 0原文

Apc不缓存文件,它只缓存用户数据。当我在本地主机上测试时,APC 缓存了我使用的所有文件。但它不适用于我的共享主机。这是配置问题吗?

这些是我的 apc.php (APC 3.0.19) 的统计数据: apc.php stats

在上图中,APC 不使用任何内存。 这就是 phpinfo() 给我的: phpinfo() output

在本地主机上,我只访问 http://localhost/test.php。 Apc 将立即缓存 localhost/test.php (类型文件)。但在共享主机上,我看不到它缓存文件(它可以缓存变量,如果我存储但不存储文件);

    apc_add('APC TEST', '123');
    echo apc_fetch('APC TEST'); //-- it work with this code

如果我访问 test.php,我想要 Apc 缓存 test.php。

是否有配置使 APC 无法缓存文件类型或共享主机的限制?

Apc doesn't cache files, it only caches user data. When I tested on localhost, APC cached all files I used. But it doesn't work on my shared hosting. Is this a configuration issue?

These are the stats from my apc.php (APC 3.0.19):
apc.php stats

On the above picture, APC doesn't use any memory.
This is what phpinfo() gives me:
phpinfo() output

On localhost, i only access http://localhost/test.php. Apc will cache localhost/test.php ( type file ) imediately. but on shared host, i don't see it cache file ( it can cache variable, if i store but don't with file );

    apc_add('APC TEST', '123');
    echo apc_fetch('APC TEST'); //-- it work with this code

i want Apc cache test.php if i access test.php.

Is there a configure make APC can't cache file type or it is limit of shared hosting?.

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

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

发布评论

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

评论(3

最佳男配角 2024-11-04 09:08:19

响应您的评论“Apc 已启用,并且 apc.cache_by_default = 1;使用 CGI 设置 php,我检查了 phpinfo();”:这就是问题所在。如果您通过 CGI 运行 PHP,则会在每次页面加载时创建一个新的 PHP 进程。由于 APC 绑定到 PHP 进程,因此它也会在每次页面访问时重新实例化。所以它显然没有任何数据。您的用户缓存示例才有效,因为您在单个页面加载时存储和获取变量。

因此:APC 无法通过 CGI 与 PHP 配合使用。使用 FastCGI(它使进程保持活动状态,从而使缓存正常工作并且通常速度更快)。

In response to your comment "Apc is enabled , and apc.cache_by_default = 1; php setup with CGI, i checked phpinfo();": That's the problem. If you run PHP over CGI a new PHP process is created on every page load. As APC is bound to the PHP process it is newly instantiated on every page access, too. So it obviously doesn't have any data in it. Your user cache example only works, because you store and fetch the variable on a single page load.

So: APC can not work with PHP over CGI. Use FastCGI (which keeps the processes alive, thus making the Cache work and generally being faster).

久随 2024-11-04 09:08:19

共享主机上 CGI 模式下的 APC 通常不可行,尽管有可能。根据您的应用程序,它也可能存在安全风险。正如 nikic 所说,你应该能够让它与 FastCGI 一起工作,但即使如此,这也不容易,具体取决于你的主机。这是一个让它发挥作用的人的详细描述。它可能会给您一些帮助,帮助您尝试使其在 CGI 模式下工作

带有 PHP 的 FastCGI APC操作码缓存

APC in CGI mode on shared hosting is generally not feasible although it may be possible. Depending on your application it may also be a security risk. As nikic said you should be able to get it working with FastCGI but even that it not easy depending on your host. Here is a detailed account of someone that got it working. It may give you some help in trying to get it to work in CGI mode

FastCGI with a PHP APC Opcode Cache

梦开始←不甜 2024-11-04 09:08:19

如果您的主机是在 fastcgi 模式下使用 php 设置的,APC 可能无法工作。你能用标准的 phpinfo() 页面检查一下吗?
编辑:我纠正了,选择的答案是正确的。我混淆了 CGI/fastcgi。是的,CGI 不起作用。但我想指出的是,即使是 fastcgi,操作码缓存也不是那么好。

If your hosting is setup with php in fastcgi mode APC may not work. can you check this with a standard phpinfo() page?
edit: I stand corrected, the chosen answer is right. I confused CGI/fastcgi. yeah CGI will not work. But I want to note that even fastcgi is not that great with opcode caching.

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