• 文件: tz.php
  • Full Path: /www/wwwroot/sh.dnmp.sh/json/pump/elf/elf/tz.php
  • Date Modified: 2026.10.25 14:20
  • File size: 8 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php


error_reporting(0); //抑制所有错误信息
@header("content-Type: text/html; charset=utf-8"); //语言强制
ob_start();
date_default_timezone_set('Asia/Shanghai');//此句用于消除时间差

$title = 'PHP探针';

$version = "v0.4.7"; //版本号



define('HTTP_HOST', preg_replace('~^www\.~i', '', $_SERVER['HTTP_HOST']));



$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 formatsize($size) 
{
	$danwei=array(' B ',' K ',' M ',' G ',' T ');
	$allsize=array();
	$i=0;

	for($i = 0; $i <5; $i++) 
	{
		if(floor($size/pow(1024,$i))==0){break;}
	}

	for($l = $i-1; $l >=0; $l--) 
	{
		$allsize1[$l]=floor($size/pow(1024,$l));
		$allsize[$l]=$allsize1[$l]-$allsize1[$l+1]*1024;
	}

	$len=count($allsize);

	for($j = $len-1; $j >=0; $j--) 
	{
		$fsize=$fsize.$allsize[$j].$danwei[$j];
	}	
	return $fsize;
}


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"><i class="fa fa-times"></i></font>';

		break;
		

		case 1:

			return '<font color="green"><i class="fa fa-check"></i></font>';

		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();

} 
//网速测试-开始
elseif($_POST['act']=="开始测试")
{
?>
	<script language="javascript" type="text/javascript">
		var acd1;
		acd1 = new Date();
		acd1ok=acd1.getTime();
	</script>
	<?php
	for($i=1;$i<=204800;$i++)
	{
		echo "<!--34567890#########0#########0#########0#########0#########0#########0#########0#########012345-->";
	}
	?>
	<script language="javascript" type="text/javascript">
		var acd2;
		acd2 = new Date();
		acd2ok=acd2.getTime();
		window.location = '?speed=' +(acd2ok-acd1ok)+'#w_networkspeed';
	</script>
<?php
}
//网速测试-结束
elseif($_GET['act'] == "Function")
{
	$arr = get_defined_functions();
	Function php()
	{
	}
	echo "<pre>";
	Echo "这里显示系统所支持的所有函数,和自定义函数\n";
	print_r($arr);
	echo "</pre>";
	exit();
}elseif($_GET['act'] == "disable_functions")
{
	$disFuns=get_cfg_var("disable_functions");
	if(empty($disFuns))
	{
		$arr = '<font color=red><i class="fa fa-times"></i></font>';
	}
	else
	{ 
		$arr = $disFuns;
	}
	Function php()
	{
	}
	echo "<pre>";
	Echo "这里显示系统被禁用的函数\n";
	print_r($arr);
	echo "</pre>";
	exit();
}



//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']."支持状况检测结果:".isfun1($_POST['funName']);

} 
elseif ($_POST['act'] == '邮件检测')
{

	$mailRe = "邮件发送检测结果:发送";
	if($_SERVER['SERVER_PORT']==80){$mailContent = "http://".$_SERVER['SERVER_NAME'].($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);}
	else{$mailContent = "http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);}
	$mailRe .= (false !== @mail($_POST["mailAdd"], $mailContent, "This is a test mail!")) ? "完成":"失败";

}


//网络速度测试
if(isset($_POST['speed']))
{
	$speed=round(100/($_POST['speed']/2048),2);
}
elseif($_GET['speed']=="0")
{
	$speed=6666.67;
}
elseif(isset($_GET['speed']) and $_GET['speed']>0)
{
	$speed=round(100/($_GET['speed']/2048),2); //下载速度:$speed kb/s
}
else
{
	$speed="<font color=\"red\">&nbsp;未探测&nbsp;</font>";
}	
	
	

// 检测函数支持

function isfun($funName = '')
{

    if (!$funName || trim($funName) == '' || preg_match('~[^a-z0-9\_]+~i', $funName, $tmp)) return '错误';

	return (false !== function_exists($funName)) ? '<font color="green"><i class="fa fa-check"></i></font>' : '<font color="red"><i class="fa fa-times"></i></font>';
}
function isfun1($funName = '')
{
    if (!$funName || trim($funName) == '' || preg_match('~[^a-z0-9\_]+~i', $funName, $tmp)) return '错误';
	return (false !== function_exists($funName)) ? '<i class="fa fa-check"></i>' : '<i class="fa fa-times"></i>';
}



//整数运算能力测试

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);

}

function GetCoreInformation() {$data = file('/proc/stat');$cores = array();foreach( $data as $line ) {if( preg_match('/^cpu[0-9]/', $line) ){$info = explode(' ', $line);$cores[]=array('user'=>$info[1],'nice'=>$info[2],'sys' => $info[3],'idle'=>$info[4],'iowait'=>$info[5],'irq' => $info[6],'softirq' => $info[7]);}}return $cores;}
function GetCpuPercentages($stat1, $stat2) {if(count($stat1)!==count($stat2)){return;}$cpus=array();for( $i = 0, $l = count($stat1); $i < $l; $i++) {	$dif = array();	$dif['user'] = $stat2[$i]['user'] - $stat1[$i]['user'];$dif['nice'] = $stat2[$i]['nice'] - $stat1[$i]['nice'];	$dif['sys'] = $stat2[$i]['sys'] - $stat1[$i]['sys'];$dif['idle'] = $stat2[$i]['idle'] - $stat1[$i]['idle'];$dif['iowait'] = $stat2[$i]['iowait'] - $stat1[$i]['iowait'];$dif['irq'] = $stat2[$i]['irq'] - $stat1[$i]['irq'];$dif['softirq'] = $stat2[$i]['softirq'] - $stat1[$i]['softirq'];$total = array_sum($dif);$cpu = array();foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 2);$cpus['cpu' . $i] = $cpu;}return $cpus;}
$stat1 = GetCoreInformation();sleep(1);$stat2 = GetCoreInformation();$data = GetCpuPercentages($stat1, $stat2);
$cpu_show = $data['cpu0']['user']."%us,  ".$data['cpu0']['sys']."%sy,  ".$data['cpu0']['nice']."%ni, ".$data['cpu0']['idle']."%id,  ".$data['cpu0']['iowait']."%wa,  ".$data['cpu0']['irq']."%ir