Displaying PHP APC Cache InformationPosted Feb. 09, 2008 in PHP
APC is the Alternative PHP Cache, which is a free, open, and robust framework for caching and optimizing PHP intermediate code. I posted about how to install APC on Linux a couple of days ago, and will now look at the apc.php script which comes with APC and shows information about how much of the cache is being used, what files are being cached, the number of times they've been accessed etc.
When you download and install the APC cache, there's a file in the root level of the source archive called apc.php - this is a PHP script which allows you to view information about the status of the PHP Cache as shown in the screenshots below. You simply need to copy the apc.php file to a directory that is served by your Apache (or other) web server and then load up the page in your browser. It's a good idea to also protect this script by use of password proection with an .htaccess file or in your httpd.conf <virtualhost> section.
The first screenshot of the APC monitor below shows host statistics. It shows which version of PHP, APC and web server are running, start and uptime of the cache, number of cached files, memory usage etc. There are numerical statistics as well as graphs.
The sceond screenshot below shows the page when clicking the "System Cache Entries" button. It shows the full path to each script filename and the number of times they've been accessed, file size, last access, last modified, when created and when deleted. It sorts them by default by the number of hits (accesses), but you can change the order by selecting different options from the drop down boxes and clicking the "Go" button.
The third screenshot below shows the screen after clicking the "Per-Directory Entries" which is similar to the "System Cache Entries" but shows a summary per directory.
The final screenshot below shows the "Version Check" page which checks to see if you are running the latest version, and a changelog of the most recent versions.
In summary, the apc.php APC cache summary PHP script is really useful for seeing how well your PHP cache is working, and what's being cached. You can monitor to make sure your cache is big enough and then change server settings to make it bigger or smaller.