0

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). Settings dump

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?

Jakub Jankowski
  • 731
  • 2
  • 9
  • 20
kadamb
  • 1,532
  • 3
  • 29
  • 55

1 Answers1

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

Yvan
  • 2,539
  • 26
  • 28
  • 1
    I did use : curl -s 127.0.0.1/clear_cache.php > /dev/null & and wrote the code in php file – kadamb Apr 20 '17 at 09:19