apc_clear_cache not working from command line in php

假如想象 提交于 2019-12-25 07:59:46

问题


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.

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

And here is my php-code

<?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?


回答1:


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

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.

You have two options:

  • call your script through FastCGI (see below)
  • call the webpage with file_get_contents() or the like, using http://

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



来源:https://stackoverflow.com/questions/40041362/apc-clear-cache-not-working-from-command-line-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!