Learn about Centmin Mod LEMP Stack today
Register Now

PHP Custom Advanced PHP Zend OpCache Status Page Centmin Mod Style!

Discussion in 'Nginx and PHP-FPM news & discussions' started by eva2000, Mar 13, 2023.

  1. eva2000

    eva2000 Administrator Staff Member

    54,363
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    4:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Been doing paid client work and wrote a more advanced PHP Zend OpCache status page for a client than what's available on the internet. The PHP OpCache status page is specifically coded for Centmin Mod LEMP stacks running PHP-FPM, including per domain breakdown of PHP OpCache cache hit/miss and memory usage metrics :)

    Just sharing the screenshots (not the code) right now.

    Advanced PHP OpCache Status Page




    The opcache.php is a single standalone PHP file and tracks PHP Zend OPCache cache metrics and useful features, including:
    • HTTP Authentication password-protected access support.
    • Cache hits, cache misses, memory usage in both tabulated forms via visual chart pie and column bar chart metrics.
    • Display PHP-FPM configuration info and PHP Extensions loaded.
    • Advance metrics that many other PHP OPCache status scripts don't have include tracking your PHP OPCache average request rate/sec and cache hit rate/sec since the PHP-FPM service start as well as average and peak max request rate/sec since the last PHP OPCache status page refresh and also min, mean, max and 99 percentile metrics for last used age for PHP files in OpCache cache.
    • Per Nginx, domain name tabulated breakdown and display of PHP OPCache cached PHP filenames, including the number of hits and memory usage. Debug output optionally displays all per Nginx domain name-specific filenames in JSON format.
    • Command Line support for ?var, ?api, and ?demo query string modes. The opcache.php script supports 3 query string feature modes:
      • opcache.php?var - Made for CLI command line use to output in JSON format all the PHP-FPM option variables and environment for the system which are normally available from phpinfo() output. They're sorted alphanumerically with exception of php.ini load config info which the very first entries in JSON array. Be careful sharing this output in public as it can reveal sensitive info and paths from your server setup.
      • opcache.php?api - Made for CLI command line use to output in JSON format all the same PHP Opcache status metrics for memory usage, cache hit/miss, request rates etc. You can script this to run a cronjob to log your PHP Opcache stats via a curl request. Not via local file though as OpCache CLI mode is disabled by default on Centmin Mod LEMP stacks.
      • opcache.php?demo - This is specifically for running opcache.php within your web browser to mask the actual domain names listed in per domain OpCache memory usage % and cache hits % column charts. This allows you to share screenshots of your charts without revealing any real domain names.
    Screenshots for advanced PHP OpCache status script for Centmin Mod LEMP stacks with per domain breakdown charts and metrics. Below is run in opcache.php?demo mode to mask real domain names. These are stats from one of my paid clients servers which pushing between 10,000 to 30,000 PHP requests/second running Centmin Mod :)

    • Pie chart breakdown of PHP OpCache hit/miss and memory usage
    • Gauge charts for current PHP OpCache cache hit and request rate per second since PHP-FPM start time
    • Gauge charts for current PHP OpCache cache hit and request rate per second since the last page refresh for advanced opcache.php script
    • Per domain break down percentages for PHP OpCache memory usage and cache hit rates.
    • Each row of charts can be collapsed/expanded to hide or show them
    cmm-custom-php-opcache-stats-page-togglecharts-demo-v2-01.png

    Then further down the page, there's extended PHP OpCache metrics and configuration info in 2 columns. The table metrics also records and reports the highest PHP OpCache cache hit rate and request rates per second since last page refresh which in this screenshot is 21,797 PHP requests/sec :)

    cmm-custom-php-opcache-stats-page-togglecharts-demo-v2-02.png

    Then there's the per Centmin Mod Nginx vhost tabulated breakdown of the domain's files in PHP OpCache cache and their respective number of cache hits and PHP OpCache memory usage. This part is useful to identify possible candidate file(s) for further optimization for use with PHP 7.4+ preload and/or PHP 8+ JIT :D

    If you toggle each domain's script debug output, you will see a full JSON array formatted listing just that domain's specific PHP files in OpCache cache.

    cmm-custom-php-opcache-stats-page-togglecharts-demo-v2-03.png

    This next screenshot demos opcache.php?api mode for JSON formatted command line output for PHP OpCache statistics so you can script logging of stats etc. The screenshot used ?json but it's now ?api :)

    cmm-custom-php-opcache-stats-page-v5-json-01.png

    Amazing what you can do with assistance from ChatGPT AI :D