Search code examples
phpapc

APC only half works


I'm trying to get APC to work as a persistent data structure.

I wrote a test script to illustrate the problem I'm running into.

<?php
    function set_true()
    {
        apc_store("test", true);
        var_dump(apc_fetch("test"));
    }

    var_dump(apc_fetch("test"));
    set_true();
?>

When I try it with apc.enable_cli=1, the following occurs:

$ php test_store.php
bool(false)
bool(true)
$ php test_store.php
bool(false)
bool(true)

That is to say, the cache seems to be wiped between each session. This make sense according to the documentation.

As for when I run it without apc.enable_cli=1, the following occurs:

$ php test_store.php
bool(false)
bool(false)
$ php test_store.php
bool(false)
bool(false)

which is to say that the cache doesn't even exist throughout the entire script (storing isn't working).

I'd like to be able to affect one singular cache which remains stored throughout the life of the server, including accesses from a client accessing PHP, including scripts I write and run from the command line, etc.


Solution

  • apc.enable_cli means that it will work in CLI, but doesn't mean that it will persist values between requests (since there is just no appropriate storage for that).

    So with apc.enable_cli it will keep the data during script run. Without it won't store it at all.

    So if you really need caching - use another caching mechanism (memcached/files/...)