JezK
Edit File: stats.php
<?php /* * This file is use to report PHP stats (when executed in the correct SAPI). * * Because it should work on a range of PHP version (4.4 - 7.x), it contains "old" code. */ function ini_value_to_bytes($val) { $val = trim($val); $unit = strtoupper(substr($val, -1)); if ($unit === 'G') { return (int) substr($val, 0, -1) * pow(1024, 3); } if ($unit === 'M') { return (int) substr($val, 0, -1) * pow(1024, 2); } if ($unit === 'K') { return (int) substr($val, 0, -1) * pow(1024, 1); } return (int) $val; } header('Content-Type: application/json'); $limited = true; if (isset($_GET['limited']) && (bool) $_GET['limited'] === false) { $limited = false; } $stats = array( // ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00 'timestamp' => date('Y-m-d\TH:i:sO'), 'serverName' => php_uname('n'), ); if (defined('PHP_MAJOR_VERSION') && defined('PHP_MINOR_VERSION')) { $stats['phpVersion'] = sprintf('%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION); } else { $version = explode('.', phpversion()); $stats['phpVersion'] = sprintf('%d.%d', $version[0], $version[1]); } if (isset($_SERVER['HTTP_HOST'])) { $stats['uri'] = $_SERVER['HTTP_HOST']; } if (isset($_SERVER['USER'])) { $stats['account'] = $_SERVER['USER']; } if (function_exists('realpath_cache_size')) { $stats['realpath_cache_size'] = array( 'configured' => ini_value_to_bytes(ini_get('realpath_cache_size')), 'real' => realpath_cache_size(), ); } if (! $limited && function_exists('realpath_cache_get')) { $stats['realpath'] = realpath_cache_get(); } if (function_exists('opcache_get_status')) { $stats['opcache'] = opcache_get_status(! $limited); } if (function_exists('apc_cache_info')) { $stats['apc'] = array(); foreach (array('system', 'user', 'filehits') as $type) { $info = apc_cache_info($type, $limited); if ($info) { $stats['apc'][$type] = $info; } } } if (function_exists('apc_sma_info')) { if (! array_key_exists('apc', $stats)) { $stats['apc'] = array(); } $stats['apc']['sma'] = apc_sma_info($limited); } if (function_exists('apcu_cache_info')) { $info = apcu_cache_info($limited); if ($info) { // It looks like the $limited flag is not working if ($limited) { if (isset($info['cache_list'])) { unset($info['cache_list']); } if (isset($info['slot_distribution'])) { unset($info['slot_distribution']); } if (isset($info['deleted_list'])) { unset($info['deleted_list']); } } $stats['apcu'] = $info; } } $options = 0; if (defined('JSON_PRETTY_PRINT')) { $options |= JSON_PRETTY_PRINT; } if (defined('JSON_UNESCAPED_SLASHES')) { $options |= JSON_UNESCAPED_SLASHES; } if (function_exists('json_encode')) { if (version_compare(PHP_VERSION, '5.3.0') >= 0) { echo json_encode($stats, $options); } else { echo json_encode($stats); } } else { // Manually export the data $json = array(); foreach ($stats as $k => $v) { if (!is_string($v)) { continue; } $json[] = sprintf('"%s": "%s"', $k, $v); } echo sprintf('{%s}', implode(",", $json)); }