Web-based Monitoring (apc.php)
APCu includes a powerful web-based dashboard, apc.php, that provides a graphical interface for monitoring and managing the cache.
Setup and Security
To use the dashboard, you must copy the apc.php file from the APCu source distribution into a directory accessible by your web server.
Security Warning: This script provides detailed information about your application's cache and allows for clearing it entirely. It is critical to secure this file. The script has a built-in basic authentication mechanism.
To enable authentication:
- Open
apc.phpin a text editor. - Set
USE_AUTHENTICATIONto1. - Change
ADMIN_USERNAMEandADMIN_PASSWORDto secure credentials.
// apc.php
defaults('USE_AUTHENTICATION', 1); // Set to 1
defaults('ADMIN_USERNAME', 'my-secure-user'); // Change this
defaults('ADMIN_PASSWORD', 'my-secure-password'); // Change this
It is also highly recommended to restrict access via web server rules (e.g., limit by IP address).
Features
The dashboard provides several views to inspect the cache's health and contents.
View Host Stats
This is the main dashboard view, offering a real-time overview of cache performance.
- General Cache Information: Displays APCu and PHP versions, shared memory configuration, and cache start time/uptime.
- Cache Information: Shows key metrics like the number of cached variables, hits, misses, and insert/request rates.
- Runtime Settings: Lists the current values of all
apc.*INI settings. - Host Status Diagrams:
- Memory Usage: A pie chart visualizing the amount of free vs. used shared memory. Multiple red slices indicate memory fragmentation.
- Hits & Misses: A bar chart showing the ratio of cache hits to misses, representing cache efficiency.
- Detailed Memory Usage and Fragmentation: Provides a detailed bar chart of memory blocks and a fragmentation percentage. High fragmentation can lead to an inability to store new items even if free memory is available.
User Cache Entries
This section allows you to inspect and manage individual items in the cache.
- Listing and Sorting: You can view active or deleted (garbage-collected) entries. The list can be sorted by various attributes like hits, size, creation time, or access time.
- Searching: A search box allows you to filter entries using regular expressions to find specific keys.
- Viewing Entry Details: Clicking on an entry's key reveals its contents, pretty-printed for readability.
- Deleting Entries: Each entry has a "Delete Now" link to remove it from the cache individually.
Version Check
This utility connects to pecl.php.net to check if you are running the latest version of APCu and displays the changelog for recent releases.
Clear Cache
When authenticated, a "Clear Cache" button is available in the main menu. Clicking this will immediately expunge the entire user cache.