Created
December 1, 2019 19:13
-
-
Save elbakerino/740a9c82a71a90c0c14b0430fa35ec4a to your computer and use it in GitHub Desktop.
PHP OpCache Status Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* Prints a nice op cache status in the PHP CLI, for that `opcache.enable_cli = 1` must be set in your opcache ini | |
* Simply run it with: php op-status.php | |
* | |
* LICENSE: MIT | |
* | |
* @author Michael Becker, https://mlbr.xyz | |
* @copyright 2019 Michael Becker | |
* @license MIT | |
*/ | |
if(!function_exists('opcache_get_status')) { | |
fwrite(STDOUT, 'No OpCache available.' . PHP_EOL); | |
exit(); | |
} | |
$status = opcache_get_status(); | |
if(!$status) { | |
fwrite(STDOUT, 'OpCache turned-off.' . PHP_EOL); | |
exit(); | |
} | |
function arrayPrinter($arr, $prefix = '') { | |
$max_len = 0; | |
foreach($arr as $lbl => $val) { | |
if(!is_array($val)) { | |
if($max_len < strlen($lbl)) { | |
$max_len = strlen($lbl); | |
} | |
} | |
} | |
foreach($arr as $lbl => $val) { | |
$lbl = ucwords(str_replace('_', ' ', $lbl)); | |
if(is_array($val)) { | |
fwrite(STDOUT, $prefix . $lbl . PHP_EOL); | |
arrayPrinter($val, ' '); | |
} else { | |
if(is_bool($val)) { | |
$val = $val ? 'y' : 'n'; | |
} | |
fwrite(STDOUT, $prefix . $lbl . ' ' . implode('', array_fill(0, $max_len - strlen($lbl) + 1, '.')) . ' ' . $val . PHP_EOL); | |
} | |
} | |
} | |
arrayPrinter($status); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment