<p >php 服务器性能检测探针文件</p>
<p ><img alt="" src="/up_pic/201211/20121106064450.jpg" /></p>
<p >function test_basic($score){<br />
$items['操作系统']=PHP_OS;<br />
$items['服务器软件']=$_SERVER["SERVER_SOFTWARE"];</p>
<p > $runMode = null;</p>
<p > $runMode = php_sapi_name();<br />
switch($runMode){<br />
case 'cgi-fcgi':<br />
$score+=50;<br />
break;<br />
}</p>
<p > $safemodeStr = '<span style="color:red">(安全模式)</span>';<br />
if($runMode){<br />
if(ini_get('safe_mode')){<br />
$runMode.='&nbsp;';<br />
}<br />
$items['php运行方式']=$runMode;<br />
}elseif(ini_get('safe_mode')){<br />
$items['php运行方式']=$safemodeStr;<br />
}</p>
<p > return array('group'=>'服务器基本信息','key'=>'basic','items'=>$items);<br />
}</p>
<p > function test_php(&$score){<br />
$items['php版本']=PHP_VERSION;<br />
if(is_callable('file_put_contents')){<br />
$score += 40;<br />
}<br />
if(is_callable('str_ireplace')){<br />
$score += 20;<br />
}<br />
if(is_callable('ftp_chmod')){<br />
$score += 10;<br />
}<br />
if(is_callable('http_build_query')){<br />
$score += 20;<br />
}</p>
<p > $items['程序最多允许使用内存量&nbsp;memory_limit']=ini_get("memory_limit");<br />
$items['POST最大字节数&nbsp;post_max_size']=ini_get("post_max_size");<br />
$items['允许最大上传文件&nbsp;upload_max_filesize']=ini_get("upload_max_filesize");<br />
$items['程序最长运行时间&nbsp;max_execution_time']=ini_get("max_execution_time");<br />
$disableFunc = get_cfg_var("disable_functions");<br />
$items['被禁用的函数&nbsp;disable_functions']=$disableFunc?$disableFunc:'无';<br />
return array('group'=>'php基本信息','items'=>$items);<br />
}</p>
<p > function test_server_req(&$score){</p>
<p ><br />
$rst = version_compare(PHP_VERSION,'4.0','>=');<br />
$items['PHP4以上'] = array(<br />
'value'=>PHP_VERSION,<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}</p>
<p > $rst = !get_cfg_var('zend.ze1_compatibility_mode');<br />
$items['zend.ze1_compatibility_mode 关闭'] = array(<br />
'value'=>$rst?'Off':'On',<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}</p>
<p > $tmpfname = tempnam("../home/cache", "foo");<br />
$handle = fopen($tmpfname, "w");<br />
$rst = flock($handle,LOCK_EX);<br />
fclose($handle);<br />
unlink($tmpfname);<br />
$items['支持文件锁(flock)'] = array(<br />
'value'=>$rst?'支持':'不支持',<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}</p>
<p > $rst = function_exists('xml_parse_into_struct');<br />
$items['php可以解析xml文件'] = array(<br />
'value'=>$rst?'支持':'不支持',<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}</p>
<p > $rst = function_exists('mysql_connect') && function_exists('mysql_get_server_info');<br />
$items['MySQL函数库可用'] = array(<br />
'value'=>$rst?mysql_get_client_info():'未安装',<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}else{<br />
$rst = false;<br />
if(defined('DB_HOST')){<br />
if(defined('DB_PASSWORD')){<br />
$rs = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);<br />
}elseif(defined('DB_USER')){<br />
$rs = mysql_connect(DB_HOST,DB_USER);<br />
}else{<br />
$rs = mysql_connect(DB_HOST);<br />
}<br />
$db_ver = mysql_get_server_info($rs);<br />
}elseif($db_ver = mysql_get_server_info()){<br />
define('DB_HOST','');<br />
}else{<br />
$sock = get_cfg_var('mysql.default_socket');<br />
if(PHP_OS!='WINNT' && file_exists($sock) && is_writable($sock)){<br />
define('DB_HOST',$sock);<br />
}else{<br />
$host = ini_get('mysql.default_host');<br />
$port = ini_get('mysql.default_port');<br />
if(!$host)$host = '127.0.0.1';<br />
if(!$port)$port = 3306;<br />
define('DB_HOST',$host.':'.$port);<br />
}<br />
}<br />
if(!$db_ver){<br />
if(substr(DB_HOST,0,1)=='/'){<br />
$fp = @fsockopen("unix://".DB_HOST);<br />
}else{<br />
if($p = strrpos(DB_HOST,':')){<br />
$port = substr(DB_HOST,$p+1);<br />
$host = substr(DB_HOST,0,$p);<br />
}else{<br />
$port = 3306;<br />
$host = DB_HOST;<br />
}<br />
$fp = @fsockopen("tcp://".$host, $port, $errno, $errstr,2);<br />
}<br />
if (!$fp){<br />
$db_ver = '无法连接';<br />
} else {<br />
fwrite($fp, "n");<br />
$db_ver = fread($fp, 20);<br />
fclose($fp);<br />
if(preg_match('/([2-8].[0-9.]+)/',$db_ver,$match)){<br />
$db_ver = $match[1];<br />
$rst = version_compare($db_ver,'3.2.23','>=');<br />
}else{<br />
$db_ver = '无法识别';<br />
}<br />
}<br />
}else{<br />
$rst = version_compare($db_ver,'3.2.23','>=');<br />
}</p>
<p > $this->db_ver = $db_ver;</p>
<p > $mysql_key = '数据库Mysql 3.2.23以上&nbsp;<i style="color:#060">'.DB_HOST.'</i>';<br />
if($this->allow_change_db){<br />
$mysql_key.='<form method="get" action="" style="margin:0;padding:0"><table><tr><td><label for="db_host">MySQL主机</label></td><td>&nbsp;</td></tr><tr><td><input id="db_host" value="'.DB_HOST.'" name="db_host" style="width:100px;" type="text" /></td><td><input type="submit" value="连接"></td></tr></table></form>';<br />
}<br />
$items[$mysql_key] = array(<br />
'value'=>$db_ver,<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}</p>
<p > $rst = (defined('OPTIMIZER_VERSION') || (function_exists('extension_loaded') && extension_loaded('Zend Optimizer')));<br />
if($rst){<br />
if(defined('OPTIMIZER_VERSION')){<br />
$rst = version_compare(OPTIMIZER_VERSION,'2.5.7','>=');<br />
$value = OPTIMIZER_VERSION;<br />
}else{<br />
$value = '通过';<br />
}<br />
}else{<br />
$value = '未安装';<br />
}</p>
<p > $items['ZEND Optimizer2.5.7以上'] = array(<br />
'value'=>$value,<br />
'result'=>$rst,<br />
);<br />
if(!$rst){<br />
$allow_install = false;<br />
}<br />
}</p>
<p > if(ini_get('safe_mode')){<br />
$rst = is_callable('ftp_connect');<br />
if(!$rst){<br />
$allow_install = false;<br />
}<br />
$items['当安全模式开启时,ftp函数可用'] = array(<br />
'value'=>$rst?'可用':'不可用',<br />
'result'=>$rst,<br />
);<br />
}</p>
<p > $rst = preg_match('/[0-9]+.[0-9]+.[0-9]+.[0-9]+/',gethostbyname('www.example.com'));<br />
$items['DNS配置完成,本机上能通过域名访问网络'] = array(<br />
'value'=>$rst?'成功':'失败 (将影响部分功能)',<br />
'result'=>$rst,<br />
);</p>
<p > return array('group'=>'基本需求','key'=>'require','items'=>$items,'type'=>'require','allow_install'=>$allow_install);<br />
}</p>