brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: opcache_get_status(false) shows the hit rate of the PHP opcode cache

Cache
~/tips/tip-cache-opcache-get-status-hit-rate

print_r( opcache_get_status( false )['opcache_statistics'] );

Prints how often PHP reuses compiled scripts and how full the opcode cache memory is.

If OPcache is full, PHP compiles scripts again and again and the site gets slower for no visible reason.

<?php
print_r( opcache_get_status( false )['opcache_statistics'] );
print_r( opcache_get_status( false )['memory_usage'] );

Run this from a page served through PHP-FPM or Apache, not from the command line. The CLI has its own OPcache state and usually has it switched off with opcache.enable_cli, so it shows nothing useful. opcache_hit_rate should be close to 100 and free_memory should not hit zero. Passing false leaves out the long list of cached scripts. Raise opcache.memory_consumption or opcache.max_accelerated_files when it fills up, and delete the test file afterwards, because it exposes server details.

Further reading: PHP manual: opcache_get_status

Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it

More Cache tips fincore /var/lib/example/data.db npm cache verify fc-cache -f -v ~/.local/share/fonts proxy_cache app; Cache-Control: no-cache All Cache tips (24) All topics

Link