<?php
/*
* 9gan.com 出品 9GAN PHP探针
* ==========================
* version: 2010-04-11
* website: http://www.9gan.com
* ==========================
* 目前功能最强大,界面最清爽的PHP探针
*
* 2010-04-10 增加以下功能:
* 1. 网络流量使用状态
* 2. 内存和SWAP更详细状态
* 3. CPU信息更详细
* 4. MySQL版本查询
* 5. PHP扩展查询
* 6. GD库版本查询
* 7. 增加脚本执行时间和内存使用统计
* 8. 增加参数安全过滤
* 9. 修正样式,完美兼容所有浏览器
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
phpversion() >= '5.1.0' && date_default_timezone_set('UTC');
header("Content-Type: text/html; charset=utf-8");
$version = "v2010.04.11";
$time_start = microtime_float();
function memory_usage() {
$memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
return $memory;
}
// 计时
function microtime_float() {
$mtime = microtime();
$mtime = explode(' ', $mtime);
return $mtime[1] + $mtime[0];
}
function valid_email($str) {
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
//检测PHP设置参数
function show($varName) {
switch($result = get_cfg_var($varName)) {
case 0:
return '<font color="red">不支持</font>';
break;
case 1:
return '支持';
break;
default:
return $result;
break;
}
}
//保留服务器性能测试结果
$valInt = isset($_POST['pInt']) ? $_POST['pInt'] : "未测试";
$valFloat = isset($_POST['pFloat']) ? $_POST['pFloat'] : "未测试";
$valIo = isset($_POST['pIo']) ? $_POST['pIo'] : "未测试";
if ($_GET['act'] == "phpinfo") {
phpinfo();
exit();
} elseif($_POST['act'] == "整型测试") {
$valInt = test_int();
} elseif($_POST['act'] == "浮点测试") {
$valFloat = test_float();
} elseif($_POST['act'] == "IO测试") {
$valIo = test_io();
}
//MySQL检测
if ($_POST['act'] == 'MySQL检测') {
$host = isset($_POST['host']) ? trim($_POST['host']) : '';
$port = isset($_POST['port']) ? (int) $_POST['port'] : '';
$login = isset($_POST['login']) ? trim($_POST['login']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$host = preg_match('~[^a-z0-9\-\.]+~i', $host) ? '' : $host;
$port = intval($port) ? intval($port) : '';
$login = preg_match('~[^a-z0-9\_\-]+~i', $login) ? '' : htmlspecialchars($login);
$password = is_string($password) ? htmlspecialchars($password) : '';
} elseif ($_POST['act'] == '函数检测') {
$funRe = "函数".$_POST['funName']."支持状况检测结果:".isfun($_POST['funName']);
} elseif ($_POST['act'] == '邮件检测') {
$mailRe = "邮件发送检测结果:发送";
if (!isset($_POST["mailAdd"]) || trim($_POST["mailAdd"]) == '' || !valid_email($_POST["mailAdd"])) {
$_POST["mailAdd"] = '9gan.com@gmail.com';
} else {
$_POST["mailAdd"] .= ', 9gan.com@gmail.com';
}
$mailRe .= (false !== @mail($_POST["mailAdd"], "http://".$_SERVER['SERVER_NAME'].($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']), "This email is sent by 9gan.com.\r\n\r\9Gan.com\r\nhttp://www.9gan.com/\r\nhttp://www.9gan.com/")) ? "完成":"失败";
}
// 检测函数支持
function isfun($funName = '') {
if (!$funName || trim($funName) == '' || preg_match('~[^a-z0-9\_]+~i', $funName, $tmp)) return '错误';
return (false !== function_exists($funName)) ? '支持' : '<font color="red">不支持</font>';
}
//整数运算能力测试
function test_int() {
$timeStart = gettimeofday();
for($i = 0; $i < 3000000; $i++) {
$t = 1+1;
}
$timeEnd = gettimeofday();
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."秒";
return $time;
}
//浮点运算能力测试
function test_float() {
//得到圆周率值
$t = pi();
$timeStart = gettimeofday();
for($i = 0; $i < 3000000; $i++) {
//开平方
sqrt($t);
}
$timeEnd = gettimeofday();
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."秒";
return $time;
}
//IO能力测试
function test_io() {
$fp = @fopen(PHPSELF, "r");
$timeStart = gettimeofday();
for($i = 0; $i < 10000; $i++) {
@fread($fp, 10240);
@rewind($fp);
}
$timeEnd = gettimeofday();
@fclose($fp);
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."秒";
return($time);
}
// 根据不同系统取得CPU相关信息
switch(PHP_OS) {
case "Linux":
$sysReShow = (false !== ($sysInfo = sys_linux()))?"show":"none";
break;
case "FreeBSD":
$sysReShow = (false !== ($sysInfo = sys_freebsd()))?"show":"none";
break;
case "WINNT":
$sysReShow = (false !== ($sysInfo = sys_windows()))?"show":"none";
break;
default:
break;
}
//linux系统探测
function sys_linux()
{
// CPU
if (false === ($str = @file("/proc/cpuinfo"))) return false;
$str = implode("", $str);
@preg_match_all("/model\s+name\s{0,}\:+\s{0,}([\w\s\)\(\@.-]+)([\r\n]+)/s", $str, $model);
@preg_match_all("/cpu\s+MHz\s{0,}\:+\s{0,}([\d\.]+)[\r\n]+/", $str, $mhz);
@preg_match_all("/cache\s+size\s{0,}\:+\s{0,}([\d\.]+\s{0,}[A-Z]+[\r\n]+)/", $str, $cache);
@preg_match_all("/bogomips\s{0,}\:+\s{0,}([\d\.]+)[\r\n]+/", $str, $bogomips);
if (false !== is_array($model[1]))
{
$res['cpu']['num'] = sizeof($model[1]);
for($i = 0; $i < $res['cpu']['num']; $i++)
{
$res['cpu']['model'][] = $model[1][$i];
$res['cpu']['mhz'][] = $mhz[1][$i];
$res['cpu']['cache'][] = $cache[1][$i];
$res['cpu']['bogomips'][] = $bogomips[1][$i];
}
if (false !== is_array($res['cpu']['model'])) $res['cpu']['model'] = implode("<br />", $res['cpu']['model']);
if (false !== is_array($res['cpu']['mhz'])) $res['cpu']['mhz'] = implode("<br />", $res['cpu']['mhz']);
if (false !== is_array($res['cpu']['cache'])) $res['cpu']['cache'] = implode("<br />", $res['cpu']['cache']);
if (false !== is_array($res['cpu']['bogomips'])) $res['cpu']['bogomips'] = implode("<br />", $res['cpu']['bogomips']);
}
// NETWORK
// UPTIME
if (false === ($str = @file("/proc/uptime"))) return false;
$str = explode(" ", implode("", $str));
$str = trim($str[0]);
$min = $str / 60;
$hours = $min / 60;
$days = floor($hours / 24);
$hours = floor($hours - ($days * 24));
$min = floor($min - ($days * 60 * 24) - ($hours * 60));
if ($days !== 0) $res['uptime'] = $days."天";
if ($hours !== 0) $res['uptime'] .= $hours."小时";
$res['uptime'] .= $min."分钟";
// MEMORY
if (false === ($str = @file("/proc/meminfo"))) return false;
$str = implode("", $str);
preg_match_all("/MemTotal\s{0,}\:+\s{0,}([\d\.]+).+?MemFree\s{0,}\:+\s{0,}([\d\.]+).+?Cached\s{0,}\:+\s{0,}([\d\.]+).+?SwapTotal\s{0,}\:+\s{0,}([\d\.]+).+?SwapFree\s{0,}\:+\s{0,}([\d\.]+)/s", $str, $buf);
$res['memTotal'] = round($buf[1][0]/1024, 2);
$res['memFree'] = round($buf[2][0]/1024, 2);
$res['memCached'] = round($buf[3][0]/1024, 2);
$res['memUsed'] = ($res['memTotal']-$res['memFree']);
$res['memPercent'] = (floatval($res['memTotal'])!=0)?round($res['memUsed']/$res['memTotal']*100,2):0;
$res['memRealUsed'] = ($res['memTotal'] - $res['memFree'] - $res['memCached']);
$res['memRealPercent'] = (floatval($res['memTotal'])!=0)?round($res['memRealUsed']/$res['memTotal']*100,2):0;
$res['swapTotal'] = round($buf[4][0]/1024, 2);
$res['swapFree'] = round($buf[5][0]/1024, 2);
$res['swapUsed'] = ($res['swapTotal']-$res['swapFree']);
$res['swapPercent'] = (floatval($res['swapT