使用 APC 忽略特定文件的缓存

发布于 2024-09-29 18:32:04 字数 310 浏览 10 评论 0原文

有没有办法防止特定文件被 APC 缓存操作码?用例如下:

位于云上的应用程序,可动态调整自身大小(根据需要启动和关闭服务器)。当新 IP 可用或不可用时,config.php 脚本必须知道它们。

由于这些更改发生得足够频繁,并且 config.php 文件相当基本,因此最好不必担心仅针对一个文件清除 APC。

从 APC 中清除单个文件绝对是一种可能,但由于您无法通过命令行访问 APC,因此该解决方案最终变得相当不优雅。

Is there a way to prevent a specific file from being opcode cached with APC? The use case is as follows:

An application that sits on the cloud, which dynamically resizes itself (spinning up and down servers as required). The config.php script must know of the new IPs as they become available or unavailable.

Since these changes happen frequently enough, and the config.php file is fairly basic, it would be ideal to not have to worry about clearing APC just for the one file.

Clearing the one file out of APC is definitely a possibility, but since you can't access APC via the command line, the solution ends up being rather inelegant.

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

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

发布评论

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

评论(3

简美 2024-10-06 18:32:04

我有一个类似的用例。我多次问过自己同样的问题,却一直找不到解决办法。然而,我的解决方案是创建一个快速脚本来负责清除每个服务器的 APC 缓存。每次重建应用程序时,我都需要使用 apc_clear_cache 点击每台服务器上的文件来清除操作码缓存。如果您只需要清除一个文件,那么最好使用 apc_compile_file< /code>

希望这有帮助。

I have a similar use case. I've asked myself the same question many times, and I have not been able to find a solution. However, my solution has been to create a quick script that takes care of clearing the APC cache for each server. Every time I rebuild the app, I need to hit the file on each server to clear the opcode cache using apc_clear_cache If you only have to clear one file, you may be better off with apc_compile_file

Hope this helps.

梦回梦里 2024-10-06 18:32:04

是的。你应该检查 apc.filter 配置指令。 另一个问题 | PHP 文档

Yes. you should check out the apc.filter configuration directive. Another Question | PHP Docs

北方的巷 2024-10-06 18:32:04

我不知道有什么方法可以做到你所建议的,但你应该能够围绕它设计你的方法。

显而易见的解决方案是不要将数据存储在 php 文件中。既然您已经有了 APC,为什么不将配置数据保留在 APC 中(作为缓存数据,而不是操作码)。

因此,无论修改 config.php,现在都会执行如下操作:

  1. 修改某些非 php 文件(something.ini 或类似文件)
  2. 使 APC 缓存条目无效。

当 config.php 需要数据时,它通常会从缓存中读取。如果缓存已失效,它将从 ini 文件中读取/解析数据,更新缓存,然后照常进行。

归根结底,您使用操作码缓存来缓存数据。您应该使用数据缓存。幸运的是,APC 两者都提供。

I don't know of a way to do what you're suggesting, but you should be able to engineer your way around it.

The obvious solution is to not store the data in a php file. Since you've already got APC, why not just keep the configuration data in APC (as cached data, not opcodes).

So whatever modifies config.php, would now do something like this:

  1. Modify some non-php file (something.ini, or something like that)
  2. Invalidate the APC cache entry.

When config.php needed the data, it would typically read from the cache. If the cache has been invalidated, it reads/parses the data from the ini file, updates the cache, and proceeds as usual.

At the end of the day, you're using an opcode cache to cache data. You should use a data cache instead. Luckily, APC provides both.

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