How to check if APC opcode cache is working fine in PHP?


I am using PHP with APC cache enabled:

apc.cache_by_default => On
apc.enabled => On
apc.ttl => 7200

Now how can I know if it is using the opcode cache 100%.

For example, let us say that I have this PHP file:

echo "Hi there";

Now after running this file, let us change it toecho "Bye there";

Shouldn't it echo "Hi there" since the TTL of 7200 seconds is not over yet? Am I right? If so, why does it echo "Bye there"? And if I am wrong how can I force it to use the opcode cache even after changing the file?




The simplest way that I could find to tell whether APC is working was to create a new PHP file containing this code...


It dumps the contents of apc_cache_info() to the screen (be careful, on a large, live site this could be lots of data!).

Every time you reload this PHP file, you should seenum_hits increase, meaning that the opcode cache was used. A miss indicates that APC had to recompile the file from source (usually done on every change).

For a nicer interface to this information you can use theapc.php file that comes with APC. I copied this to my website directory using this console command (your folder locations may differ)...

cp /usr/share/doc/php-apc/apc.php /usr/share/nginx/html/apc-stats.php

Running this file in your browser gives you nice colours and graphs!

See this link for further info:

People are also looking for solutions to the problem: java - expectation failed in android during photo upload


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.