本文介绍了apc_clear_cache无法从php中的命令行运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个清除apc的php脚本.当我使用浏览器打开脚本时,该脚本运行良好,但是当我从命令行运行该文件时,则不会清除缓存.

I have a php script which clears apc.The script is working fine, when I opening it using browser, but when I am running that file from command line, it is not clearing cache.

我检查了apc.enable_cli设置,该设置也处于启用状态(请检查屏幕截图).

I checked for apc.enable_cli setting, and that is also on (check the screenshot).

这是我的PHP代码

<?php

if (isset($argv[1])) {
    $key = $argv[1];

    $info = apc_cache_info("user");
    foreach ($info['cache_list'] as $obj) {
        if (strstr($obj['info'], $key)) {
            apc_delete($obj['info']);
        }
    }

} else {
    apc_clear_cache("user");
}
?>

我想念什么或做错什么了?

What am I missing or doing wrong?

推荐答案

您无法从命令行清除APC缓存,因为您没有访问Web服务器的同一APC段.

You can't clear APC cache from command-line, as you're not hitting the same APC segment of your webserver.

请注意,enable_cli仅允许您在CLI环境中使用APC,但可以为脚本创建一个段,并在脚本末尾销毁它.它不使用同一段,因为它不了解您的Web服务器.

Note that enable_cli only allows you to use APC in a CLI environment, but creates a segment for your script, and destroy it at the end of the script. It doesn't use the same segment because it doesn't know about your webserver.

您有两个选择:

  • 通过FastCGI调用脚本(见下文)
  • 使用http://
  • file_get_contents()等调用网页

如果您需要访问APC数据,还可以阅读我的文章: https://www.dugwood.com/949904-php5-opcode-caching-and-memory-storage- with-apc-xcache-in-command-line-interface-cli-or-cron.html

If you need to access APC data, you can also read my article: https://www.dugwood.com/949904-php5-opcode-caching-and-memory-storage-with-apc-xcache-in-command-line-interface-cli-or-cron.html

这篇关于apc_clear_cache无法从php中的命令行运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:23