Single-file APCu dashboard for modern PHP versions.
apcu-stats.php provides:
- APCu health/status metrics (hits, misses, rates, memory, fragmentation)
- cache entry browser with search, sorting, and limit (only with authenticated edit credentials)
- delete single key
- clear entire APCu cache
- statistics-only default mode unless edit credentials are configured in the file
- PHP 8.1+ (tested with PHP 8.5)
- APCu extension enabled (
apc.enabled=1) - for CLI server/testing:
apc.enable_cli=1
- Place
apcu-stats.phpin a web-accessible directory. - Open it in your browser, for example:
http://localhost/apcu-stats.php - Optional: enable write actions by setting constants inside
apcu-stats.php:APCU_STATS_EDIT_USERAPCU_STATS_EDIT_PASS
Example (temporary, local):
php -d apc.enable_cli=1 -S 127.0.0.1:8080 -t .Then open http://127.0.0.1:8080/apcu-stats.php.
- By default (
APCU_STATS_EDIT_USER/APCU_STATS_EDIT_PASSempty), dashboard runs in statistics-only mode. - In statistics-only mode, key browsing/search and all write actions are hidden or server-side blocked.
- If credentials are configured, open
?auth=1once to trigger HTTP Basic Auth in the browser, then entry browsing and write actions are unlocked. - On some shared hosting (CGI/FastCGI), PHP does not receive Basic Auth variables automatically.
In that case, add this to
.htaccessin the same directory:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%1]- The parameters below are only effective after successful authentication (
?auth=1). q: key search filter (substring)sort:hits|size|ttl|created|access|keydir:asc|desclimit: number of rows (10-1000)refresh: auto refresh interval in seconds (0|5|10|30|60|120|300)
Example:
/apcu-stats.php?q=user:&sort=size&dir=desc&limit=200
Deletebutton per key: removes one APCu keyClear cache: clears complete user cache- both actions are protected by CSRF token
- without configured and authenticated edit credentials, entry browsing and write actions are locked
- The dashboard includes two dedicated info tiles in the stats grid:
Scope: shows that APCu metrics are per worker processWorker Status: indicates whether the current worker started recently
- APCu
uptimeand visible entries are per PHP worker process, not global for all workers. - On shared hosting, requests may hit different workers or restarted workers, so uptime can jump/reset and entry lists can differ between reloads.
- If cache fills up, APCu can evict entries automatically (
expungesincreases); this is expected behavior.
docker compose up --build apcu-statsOpen http://127.0.0.1:8080/apcu-stats.php.
To allow write actions in Docker, edit apcu-stats.php and set APCU_STATS_EDIT_USER + APCU_STATS_EDIT_PASS.
Integration tests are included and cover:
- dashboard render
- seeded entry listing
- statistics-only lock for key browsing/search
- statistics-only lock behavior for write actions
- server-side rejection of write POST requests in statistics-only mode
- auth prompt behavior (
?auth=1) with and without configured credentials - auth prompt rejection with wrong credentials
- authenticated entry browsing/search visibility
- authenticated delete, clear, and CSRF validation flows
docker compose run --rm testYou need local PHP CLI with APCu enabled:
bash tests/run-integration.sh