PHP "apc_store" and "apc_fetch" do not work as expected

I tried to use APC, but it does not work as I expected.

file1:

$bar = 'BAR'; apc_store('foo', $bar, 3600); var_dump(apc_fetch('foo')); // It works here. Displays BAR 

file2:

 var_dump(apc_fetch('foo')); 

When I execute file2 for a few seconds, it returns false instead of "BAR", which is the data stored in the cache.

+7
php caching apc
source share
2 answers

It works fine :) - as long as you remember that each php script executed from the command line uses its own cache, so you cannot access the data saved by script1 inside script2. (you cannot access it at a later start to script1, since it clears when the script ends)

These caches are also separate from the cache that you most likely want to use, and that the php script cache is executed through your web server.

So, if you have those tests that have been saved on your website so that you can access, for example, http: //localhost/file1.php , then http: //localhost/file2.php

It will work as expected.

It also means that you cannot clear the web server cache server from the command line. The caching code (user cache or operation code) must be executed through your web server. It will be wget from shell or file_get_contents () from php cli - according to your taste and circumstances.

+4
source share

Install this ( http://svn.php.net/viewvc/pecl/apc/trunk/apc.php?view=markup ) in the protected area of ​​the server, configure it as a description in the comments, and this should make it diagnose your caching problems APC, wind, or at least give you a better idea of ​​why something is not working as desired.

0
source share

All Articles