支持多级目录建立的php函数

 更新时间:2016年11月25日 16:27  点击:1440
本函数php自定义函数是一款建立文件夹的路径并且支持多级目录实例函数哦。
 代码如下 复制代码

 * create_dir(建立文件夹的路径,支持多级目录);
 */
 function create_dir($dir_adds='') {
  $falg = true;
  $dir_adds  = trim($dir_adds);
  if($dir_adds!=''){
   $dir_adds = str_replace(array('//','\','\\'),'/',$dir_adds);
   if (!is_dir($dir_adds)) {
    $temp = explode('/',$dir_adds);
    $cur_dir = '';
    for($i=0;$i<count($temp);$i++){
     $cur_dir .= $temp[$i].'/';
     if (!@is_dir($cur_dir)) {
      if(!@mkdir($cur_dir,0777))
       $falg = false;
     }
    }
   }
   return $falg;
  }
 }
 
 //看一款目录检测并写文件函数
 
 function htm_w(
    $w_dir = '',
    $w_filename = '',
    $w_content = ''
   ){

  $dvs  = '';
  if($w_dir && $w_filename && $w_content){
   //目录检测数量
   $w_dir_ex  = explode('/',$w_dir);
   $w_new_dir = ''; //处理后的写入目录
   unset($dvs,$fdk,$fdv,$w_dir_len);
   foreach((array)$w_dir_ex as $dvs){
    if(trim($dvs) && $dvs!='..'){
     $w_dir_len .= '../';
     $w_new_dir .= $dvs.'/';
     if (!@is_dir($w_new_dir)) @mkdir($w_new_dir, 0777);
    }
   }


   //获得需要更改的目录数
   foreach((array)$this->filedir as $fdk=>$fdv){
    $w_content = str_replace($fdv,$w_dir_len.str_replace('../','',$fdv),$w_content);
   }
   $this->writer($w_dir.$w_filename,$w_content);
  }
 }
 ?>

txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid,jar,jad,exe,html,htm,css,js,doc上传,音乐文件等都可以。
 代码如下 复制代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php文件上传</title>
</head>

<body>
<form action="uploadsir.php" method="post"  enctype="multipart/form-data"><input name="filedata" type="file" id="filedata" />
<input type="submit" name="submit" value="上传" /></form>
<?php
if(!$_post)die();
$state=uploadfile('filedata');
if($state['err']){
die('<script>alert("上传出错:'.$state['msg'].'");history.go(-1);</script>');
}

echo'<object type="application/x-shockwave-flash" data="template/images/copy.swf?u='.weburl.$state['msg'].'" width="100" height="40">
<param name="movie" value="copy.swf?u='.weburl.$state['msg'].'" />';


function uploadfile($inputname)
{
 $immediate=$_get['immediate'];
 $attachdir='../pictures';//上传文件保存路径,结尾不要带/
 $urldir="../pictures";
 $dirtype=2;//1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
 $maxattachsize=2097152;//最大上传大小,默认是2m
 $upext='txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid,jar,jad,exe,html,htm,css,js,doc';//上传扩展名
 
 $err = "";
 $msg = "";
 $upfile=$_files[$inputname];
 if(!empty($upfile['error']))
 {
  switch($upfile['error'])
  {
   case '1':
    $err = '文件大小超过了php.ini定义的upload_max_filesize值';
    break;
   case '2':
    $err = '文件大小超过了html定义的max_file_size值';
    break;
   case '3':
    $err = '文件上传不完全';
    break;
   case '4':
    $err = '无文件上传';
    break;
   case '6':
    $err = '缺少临时文件夹';
    break;
   case '7':
    $err = '写文件失败';
    break;
   case '8':
    $err = '上传被其它扩展中断';
    break;
   case '999':
   default:
    $err = '无有效错误代码';
  }
 }
 elseif(empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none')$err = '无文件上传';
 else
 {
   $temppath=$upfile['tmp_name'];
   $fileinfo=pathinfo($upfile['name']);
   $extension=$fileinfo['extension'];
   if(preg_match('/'.str_replace(',','|',$upext).'/i',$extension))
   {
    $filesize=filesize($temppath);
    if($filesize > $maxattachsize)$err='文件大小超过'.$maxattachsize.'字节';
    else
    {
     switch($dirtype)
     {
      case 1: $attach_subdir = 'day_'.date('ymd'); break;
      case 2: $attach_subdir = 'month_'.date('ym'); break;
      case 3: $attach_subdir = 'ext_'.$extension; break;
     }
     $attach_dir = $attachdir.'/'.$attach_subdir;
     if(!is_dir($attach_dir))
     {
      @mkdir($attach_dir, 0777);
      @fclose(fopen($attach_dir.'/index.htm', 'w'));
     }
     php_version < '4.2.0' && mt_srand((double)microtime() * 1000000);
     $filename=date("ymdhis").mt_rand(1000,9999).'.'.$extension;
     $target = $urldir.'/'.$attach_subdir.'/'.$filename;
     
     move_uploaded_file($upfile['tmp_name'],$target);
     if($immediate=='1')$target='!'.$target;
     $msg=str_replace('../',"",$target);
    }
   }
   else $err='上传文件扩展名必需为:'.$upext;

   @unlink($temppath);
 }
 return array('err'=>$err,'msg'=>$msg);
}
?>
</body>
</html>

php 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。

 * author:陈凯
 * data:2010-09-15
 * 文章分页类
 */

 代码如下 复制代码

class contentpage
{
 private $content;  //文章内容
 private $pagesize;    //每页最少字节数
 private $breakflag;  //分页符(可以自定义,默认为)
 private $pageurl;  //url地址
 private $pagevar;  //分页参数
 public  $pagecount;  //总页数
 public  $page;   //当前页码
 public  $pagebreak;  //每页起始位置

 function __construct($content = "",$pagesize = 10,$breakflag =" ",$pageurl = '',$pagevar = 'p')
 {
  $this->content   = $content;
  $this->pagesize  = $pagesize;
  $this->breakflag = $breakflag;
  $this->pageurl   = $pageurl;
  $this->pagevar   = $pagevar;
  $this->getpages();
 }

 //总页数,每页的起始位置和结束位置
 public function getpages()
 {
  $contentlen   = strlen($this->content); //文章总字节数
  $this->pagebreak[0] = 0;
  $i = 0;
  $offset = $this->pagesize;
  
  for ($k=0;$k<$contentlen/$this->pagesize;$k++)
  {
   if($offset > $contentlen)
   {
    $i++;
    $this->pagebreak[$i] = $contentlen;
    break;
   }
   //查找$this->pagevar出现的位置
   $where = strpos($this->content,$this->breakflag,$offset);
   if($where > $contentlen or intval($where) < 1)
   {
    $i++;
    $this->pagebreak[$i] = $contentlen;
    break;
   }
   else
   {
    $i++;
    $this->pagebreak[$i] = $where;
    $offset = $where + $this->pagesize;
   }
  }
  $this->pagecount = $i;
  if(isset($_get[$this->pagevar]) && $_get[$this->pagevar] >1 && $_get[$this->pagevar] <= $this->pagecount)
  {
   $this->page = $_get[$this->pagevar];
  }
  else
  {
   $this->page = 1;
  }
 }

 //每页内容
 function getpage()
 {
  //截取当前页码的数据
  if($this->page > 1)
  {
   return substr($this->content,$this->pagebreak[$this->page-1]+1,$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
  }
  else
  {
   return substr($this->content,$this->pagebreak[$this->page-1],$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
  }

 }

 //分页条
 public function getpagenav()
 {
  if($this->page > 1)
  {
   $pagenav = "<a href='".$this->geturl()."=".($this->page-1)."' class='div'>上一页</a>&nbsp;&nbsp;";
  }

  //输出数字页码
  for($j=1;$j<=$this->pagecount;$j++)
  {
   if($j == $this->page)
   {
    $pagenav .= "<span class='divsi'>".$j."</span>&nbsp;&nbsp;";
   }
   else
   {
    $pagenav .= "<a href='".$this->geturl()."=".$j."' class='div'>".$j."</a>&nbsp;&nbsp;";
   }
  }
  //下一页
  if($this->page < $this->pagecount && $this->pagecount >1)
  {
   $pagenav .= "<a href='".$this->geturl()."=".($this->page+1)."' class='div'>下一页</a>&nbsp;&nbsp;";
  }
  return $pagenav;
 }
 //获取url地址
 public function geturl()
 {
  $url = $_server['request_uri'];
  $parse_url = parse_url($url);
  $query_url = $parse_url['query'];
  
  if($query_url)
  {
   $query_url = ereg_replace("(^|&)".$this->pagevar."=".$this->page,"",$query_url);
   $url = str_replace($parse_url['query'],$query_url,$url);
   if($query_url)
   {
    $url .= "&".$this->pagevar;
   }
   else
   {
    $url .= $this->pagevar;
   }
  }
  else
  {
   $url .= "?".$this->pagevar;
  }
  return $url;
 }
}

$content = "第一页:文章内容分页阿斯顿浪费空间阿斯顿来看福建省地方吉林省福建路口附近大手拉飞机上浪费的说浪费监理费
第二页:阿斯顿房间阿双方了解啊对萨拉开发记得谁来付款将令对方空间的来福建阿里是否
第三页:欧文炯诶哦生地拉开方面来看就继续超文章内容分页滤机蓝卡
第四页:欧文日据拉萨及发动四分啊就双方的将爱是发觉是文章内容分页否了。";
$model = new contentpage($content);
echo $model->getpage();  //输出分页内容
echo $model->getpagenav(); //输出页码
?>

<style type="text/css教程">
<!--
body {
 width:800px;
 margin:0 auto;
 margin-top:50px;
 font-size:12px;
}
a {
 color:#014ccc;
 text-decoration:none;
}
.div {
 float:left;
 cursor:pointer;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 border:#bbdded solid 1px;
}
.divs {
 float:left;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 border:#cccccc solid 1px;
}
.divsi {
 float:left;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 background:#3399ff;
 color:#ffffff;
 border:#cccccc solid 1px;
}
.div:hover {
 background:#3399ff;
 color:#ffffff;
}
.divsi:hover {
 background:#3399ff;
 color:#ffffff;
}

-->
</style>

本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,可以支持无限级目录的管理哦。
 代码如下 复制代码

include("class.php");
$path = $_get['path'];
if($path == ""){
 $path = "dir"; 
}else{
 if(!strstr($path,"dir")){
  $path = "dir/".$path;
 }else{
  $path = $path; 
 }
}

$newdir = new dirver();
$newdir -> setpath($path);
$newdir -> dirdata();
$files = $newdir -> getfiles();
$dirs = $newdir -> getdirs();
//print_r($files);
//print_r($dirs);

echo('<link href="style.css教程" rel="stylesheet" type="text/css" />');
$max = 3;
$j = 0;
if(count($dirs) == 2){
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
 print("<td width='33%'><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[0].'">');
 print($dirs[0]);
 print('</a>');
 print("</td>");
 print("<td width='33%'><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[1].'">');
 print($dirs[1]);
 print('</a>');
 print("</td>");
 print("<td width='33%'>");
 print("&nbsp;&nbsp;");
 print("</td>");
 echo '</tr></table>';
}else{
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
while($j <= (count($dirs) -1)){
 print("<td ><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[$j].'">');
 print($dirs[$j]);
 print('</a>');
 print("</td>");
 if(($j + 1) % $max == 0){
   echo '</tr>';
   if(($j + 1) != count($dirs)){
    echo '<tr>';
     }
  }
  $j++;
 }
 echo '</tr></table>';
}
$i = 0;
if(count($files) == 2){
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
 print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[0]).".png'/>&nbsp;");
 print($newdir -> change2line($files[0]));
 print("</td>");
 print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[1]).".png'/>&nbsp;");
 print($newdir -> change2line($files[1]));
 print("</td>");
 print("<td width='33%'>");
 print("&nbsp;&nbsp;");
 print("</td>");
 echo '</tr></table>';
}else{
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
while($i <= (count($files) -1)){
 print("<td width=100><img src='type/".$newdir -> getfiletype($files[$i]).".png'/>&nbsp;");
 print($newdir -> change2line($files[$i])); 
 print("</td>");
 if(($i + 1) % 3 == 0){
   echo '</tr>';
   if(($i + 1) != count($files)){
    echo '<tr>';
    }
 }
 
 $i++;
}
 echo '</tr></table>';
}
?>


class.php

<?php
  class for php4.x
 class  dirver{
  /class var/
  var $path;
  var $flies;
  var $dirs;
  /
  function dirver(){
   $this -> path = ""; 
   $this -> files = array();
   $this -> dirs = array();
  }
  
  function dirdata(){
   if(isset($this -> path)){
    $handle = dir($this -> path);
    while(false !== ($data = $handle -> read())){
     if(is_dir($this -> connectname($this -> path,$data)) && $data != "." && $data != ".."){
       $this -> dirs[] = $data;
       continue;
      }
      
     if($data != "." && $data != ".." && is_file($this -> connectname($this -> path,$data))){
       $this -> files[] = $data;
       continue;
      }
     
    }
    $handle -> close(); 
   }else{
    return false; 
   }
  }
  
 function setpath($src){
   if($src != ""){
    $this -> path = $src; 
   }else{
    return false; 
   }
  }
 /
 function connectname($path,$name){
  return $path."/".$name;
 }
 /
 function change2line($name){
  $basename = explode(".",$name);
  $basename = $basename[0];
  $tmp = $this -> path."/".$name;
  $tmp = '<a href="'.$tmp.'" target="_blank">'.$basename.'</a>';
  return $tmp; 
 }
 
 function getfiletype($file){
  if($file != ""){
   $tmp = explode(".",$file);
   $type = $tmp[count($tmp)-1];
   return $type; 
  }
 }
 
 
 function getfiles(){
  return $this -> files;
  }
 
 function getdirs(){
  return $this -> dirs; 
  }
 //
 }

?>

/

 代码如下 复制代码

*  一、本程序基于div+css教程 新型架构php探针,免费开源的自由软件,功能强大,结构清晰,使用方便。
  1.支持windows,linux,unix,freebsd,sun solar系统
  2.支持ie6,ie7,firefox,google chrome等浏览器。
  
  二、主要用途及适用对象:
  1.熟悉php编程的业余爱好者及专业开发人员。
  2.机房管理人员配置linux(windows)+php+mysql教程+zend系统环境,检测系统是否配置成功。
  3.对于购买虚拟主机的用户,用于测试服务器性能。
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
 //////////////////以下两变量可以修改配制
 //如果这个探针你是用来验示的,你可以在下面变量中输入相关信息(会显示在页面底部
    header("content-type: text/html; charset=utf-8");
    error_reporting(e_error | e_warning | e_parse);
 ob_start();
    
    $valint = (false == empty($_post['pint']))?$_post['pint']:"未测试";
    $valfloat = (false == empty($_post['pfloat']))?$_post['pfloat']:"未测试";
    $valio = (false == empty($_post['pio']))?$_post['pio']:"未测试";
    $mysqlreshow = "none";
    $mailreshow = "none";
    $funreshow = "none";
    $opreshow = "none";
    $sysreshow = "none";
//============   定义常量 用于替换模板输出变量  =======================
  //define("yes", "<span class='resyes'>yes</span>");
  //define("no", "<span class='resno'>no</span>");
  define("yes", "<span class='resyes'>√</span>");
  define("no", "<span class='resno'>×</span>");

//=================================================================
    define("icon", "<span class='icon'>2</span>&nbsp;");
    $phps教程elf = $_server[php_self] ? $_server[php_self] : $_server[script_name];
    define("phpself", preg_replace("/(.{0,}?/+)/", "", $phpself));
    
    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'] == "connect")
    {
        $mysqlreshow = "show";
        $mysqlre = "mysql连接测试结果:";
        $mysqlre .= (false !== @mysql_connect($_post['mysqlhost'], $_post['mysqluser'], $_post['mysqlpassword']))?"mysql服务器连接正常, ":"mysql服务器连接失败, ";
        $mysqlre .= "数据库教程 <b>".$_post['mysqldb']."</b> ";
        $mysqlre .= (false != @mysql_select_db($_post['mysqldb']))?"连接正常":"连接失败";
    }
    elseif($_post['act'] == "sendmail")
    {
        $mailreshow = "show";
        $mailre = "mail邮件发送测试结果:发送";
        $mailre .= (false !== @mail($_post["mailreceiver"], "uenuprobe mail server test.", "this email is sent by uenuprobe. copyright uenucom http://www.uenu.com"))?"完成":"失败";
    }
    elseif($_post['act'] == "function_check")
    {
        $funreshow = "show";
        $funre = "函数 <b>".$_post['funname']."</b> 支持状况检测结果:".isfun($_post['funname']);
    }
    elseif($_post['act'] == "configuration_check")
    {
        $opreshow = "show";
        $opre = "配置参数 <b>".$_post['opname']."</b> 检测结果:".getcon($_post['opname']);
    }
 
//========================================================================

//========================================================================
   switch (php_os)
    {
        case "linux":
        $sysreshow = (false != ($sysinfo = sys_linux()))?"show":"none";
        break;
        case "freebsd":
        $sysreshow = (false != ($sysinfo = sys_freebsd()))?"show":"none";
        break;
  case "windows":
        //$sysreshow = (false != ($sysinfo = sys_windows()))?"show":"none";
  $sysinfo['uptime'] ="对不起windows系统不支持";
        break;
        default:
        break;
    }
    
//========================================================================

?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="common/control.css">
<script type="text/网页特效" language="javascript" src="common/admin.otable.js"></script>
<script type="text/javascript" language="javascript" src="common/include.func.js"></script>
<title>服务器信息</title>
<style type="text/css">
.resyes {
 font-size: 12px;
 color: #090;
 font-weight:bold;
 font-family: verdana;
}
.resno {
 font-size: 12px;
 color: #f00;
 font-weight:bold;
 font-family: verdana;
}
.check00{
 color: #630; 
}
</style>
<script type="text/javascript">
window.onload=function(){
 var otable=document.getelementbyid("otable");
 for(var i=0;i<otable.rows.length;i++){
  if(i%2==0) //偶数行时
   otable.rows[i].classname="altrow";
 }
 
 var otable2=document.getelementbyid("otable2");
 for(var i=0;i<otable2.rows.length;i++){
  if(i%2==0) //偶数行时
   otable2.rows[i].classname="altrow";
 }
 
 var otable3=document.getelementbyid("otable3");
 for(var i=0;i<otable3.rows.length;i++){
  if(i%2==0) //偶数行时
   otable3.rows[i].classname="altrow";
 }
 
 var otable4=document.getelementbyid("otable4");
 for(var i=0;i<otable4.rows.length;i++){
  if(i%2==0) //偶数行时
   otable4.rows[i].classname="altrow";
 }
 
 var otable5=document.getelementbyid("otable5");
 for(var i=0;i<otable5.rows.length;i++){
  if(i%2==0) //偶数行时
   otable5.rows[i].classname="altrow";
 }
}
</script>
</head>

<body class="contentbody">
<div class="maindiv">
<span class="ctitle">服务器信息</span>
<ul class="cmenu">
 <li><a href="server_info.php?action=">服务器特征</a></li>
 <li><a href="server_info.php?action=phpinfo">php基本特征</a></li>
 <li><a href="server_info.php?action=otherinfo">php组件支持状况</a></li>
 <li><a href="server_info.php?action=dbinfo">数据库支持状况</a></li>
 <li><a href="server_info.php?action=testinfo">性能检测</a></li>
    <li><a href="server_moreinfo.php">服务器详细信息</a></li>
</ul>

<div class="concontent">
<?php
switch($_get['action']){
 case '':
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="2" align="center">服务器特征</th>
</tr>
<tr>
 <td width="150">服务器时间</td>
    <td><?php echo gmdate("y年m月d日 h:i:s",time());?>&nbsp;(格林威治标准时间)&nbsp;&nbsp;<?php echo gmdate("y年n月j日 h:i:s",time()+8*3600)?>&nbsp;(北京时间)</td>
</tr>
<tr>
    <td>服务器域名</td>
    <td><?php echo("<a href="http://$_server[server_name]"  title=访问此域名 target=_blank>$_server[server_name]</a>"); ?></td>
</tr>
<tr>
 <td>服务器ip地址</td>
    <td><?php $host_ip=gethostbyname($_server["server_name"]); echo($host_ip);?></td>
</tr>
<tr>
 <td>服务器操作系统</td>
    <td><?php $os = explode(" ", php_uname()); echo $os[0]; echo "&nbsp;&nbsp;";
 if ($os[0] =="windows") {echo "主机名称:".$os[2];} else {echo "内核版本:".$os[2];}?></td>
</tr>
<tr>
 <td>服务器运行时间</td>
    <td><?php if ($sysinfo['uptime']!=""){ echo $sysinfo['uptime'];} else  echo "对不起windows系统不支持"; ?></td>
</tr>
<tr>
 <td>服务器操作系统文字编码</td>
    <td><?php echo($_server["http_accept_language"]); ?></td>
</tr>
<tr>
 <td>服务器解译引擎</td>
    <td><?php echo($_server["server_software"]); ?></td>
</tr>
<tr>
 <td>web服务端口</td>
    <td><?php echo($_server["server_port"]); ?></td>
</tr>
<tr>
 <td>服务器管理员</td>
    <td><a href="mailto:<?php echo $_server['server_admin'];?>"><?php echo $_server['server_admin'];?></a></td>
</tr>
<tr>
 <td>本文件路径</td>
    <td><?php echo($_server["script_filename"]);?></td>
</tr>
<tr>
 <td>服务端剩余空间</td>
    <td><?php echo intval(diskfreespace(".") / (1024 * 1024)).'mb';?></td>
</tr>
<tr>
 <td>系统当前用户名</td>
    <td><?php echo @get_current_user();?></td>
</tr>
</table>
<br />
<!-- 仅在windows 环境中输出-->
<?php if(("show" !==$sysreshow) & ("0"!= $_env["number_of_processors"])& (""!= $_env["number_of_processors"])){?>
<div class="info3">服务器处理器</div><div class="info4">cpu个数:<?php echo $_env["number_of_processors"]?> <?php echo "&nbsp;&nbsp;".$_env["processor_identifier"]; echo "&nbsp;&nbsp;运行级别:".$_env["processor_level"]; echo "&nbsp;&nbsp;版本:".$_env["processor_revision"];?></div>
<?php }?>
<!-- 仅在windows 环境中输出结束-->
<!-- linux or unix 参数输出-->
<?php if(("show"==$sysreshow)&("0" != $sysinfo['cpu']['num'])&("" != $sysinfo['cpu']['num'])){?>
<div class="info3">服务器处理器</div><div class="info4">cpu个数:<?php echo $sysinfo['cpu']['num']?> &nbsp;&nbsp;<?php echo $sysinfo['cpu']['detail']?></div>
<?php }?>
<?php if("show"==$sysreshow){?>
<div class="info3">内存使用状况</div><div class="info4">
<?php echo $sysinfo['memtotal']?>m, 已使用
<?php echo $sysinfo['memused']?>m, 空闲
<?php echo $sysinfo['memfree']?>m, 使用率
<?php echo $sysinfo['mempercent']?>%</div>
<div class="info3">swap区</div><div class="info4">
共<?php echo $sysinfo['swaptotal']?>m, 已使用
<?php echo $sysinfo['swapused']?>m, 空闲
<?php echo $sysinfo['swapfree']?>m, 使用率
<?php echo $sysinfo['swappercent']?>%</div>
<div class="info3">系统平均负载</div><div class="info4"><?php echo $sysinfo['loadavg']?></div>
<?php }?>
<!-- linux or unix 参数输出结束-->
<?php
  break;
 case 'phpinfo':
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">php基本特征</th>
</tr>
<tr>
 <td width="30%">php版本</td>
    <td width="20%"><?php echo php_version;?></td>
 <td width="30%">php运行方式</td>
    <td><?php /**strtoupper(php_sapi_name());**/ echo ucwords(php_sapi_name());?></td>
</tr>
<tr>
 <td>支持zend编译运行&nbsp;&nbsp;(<?php if($zend="yes") {echo "版本:";echo zend_version();}?>)</td>
    <td><?php echo $zend=(get_cfg_var("zend_optimizer.optimization_level")||get_cfg_var("zend_extension_manager.optimizer_ts")||get_cfg_var("zend_extension_ts")) ?yes:no?></td>
 <td>运行于安全模式</td>
    <td><?php if(get_cfg_var("safemode")){echo("是");}else echo("否"); ?></td>
</tr>
<tr>
 <td>自动定义全局变量&nbsp;register_globals</td>
    <td><?php echo @get_cfg_var("register_globals")?'on' : 'off';?></td>
 <td>允许使用url打开文件allow_url_fopen</td>
    <td><?php echo get_cfg_var("allow_url_fopen")=="1"?yes:no?></td>
</tr>
<tr>
 <td>允许动态加载链接库enable_dl</td>
    <td><?php echo get_cfg_var("enable_dl")=="1"?yes:no?></td>
 <td>显示错误信息&nbsp;display_errors</td>
    <td><?php echo get_cfg_var("display_errors")=="1"?yes:no?></td>
</tr>
<tr>
 <td>短标记&lt;? ?&gt;支持</td>
    <td><?php echo @get_cfg_var("short_open_tag")?yes:no;?></td>
 <td>标记&lt;% %&gt;支持</td>
    <td><?php echo @get_cfg_var("asp教程_tags")?yes:no;?></td>
</tr>
<tr>
 <td>cookie支持</td>
    <td><?php echo isset($http_cookie_vars)?yes:no;?></td>
 <td>session支持</td>
    <td><?php echo function_exists(session_start)?yes:no;?></td>
</tr>
<tr>
 <td>浮点运算有效数字显示位数</td>
    <td><?php echo @get_cfg_var("precision");?></td>
 <td>强制y2k兼容</td>
    <td><?php echo @get_cfg_var("y2k_compliance")?yes:no;?></td>
</tr>
<tr>
 <td>被禁用的函数disable_functions</td>
    <td><?php $disused = @get_cfg_var("disable_functions")?"1":"0";
if($disused =="1")
{echo '<a href="#" title="
'.@get_cfg_var("disable_functions").'
">'."more".'</a>';}
else {echo "none";}?></td>
 <td>程序最长运行时间max_execution_time</td>
    <td><?php echo(get_cfg_var("max_execution_time")."秒");?></td>
</tr>
<tr>
 <td>程序最多允许使用内存量 memory_limit</td>
    <td><?php echo @get_cfg_var("memory_limit");?></td>
 <td>post最大字节数&nbsp;post_max_size</td>
    <td><?php echo @get_cfg_var("post_max_size");?></td>
</tr>
<tr>
 <td>允许最大上传文件&nbsp;upload_max_filesize</td>
    <td><?php echo @get_cfg_var("file_uploads")?@get_cfg_var("upload_max_filesize") : $error;?></td>
 <td>php信息 phpinfo</td>
    <td><?php echo (false!==eregi("phpinfo",$disfuns))?no:"<a href='$phpself?act=phpinfo' target='_blank' class='static'>phpinfo</a>"?></td>
</tr>
<tr>
 <td>html错误显示</td>
    <td><?php echo @get_cfg_var("html_errors")?yes:no;?></td>
 <td>调试器地址/端口</td>
    <td><?php echo $debugerhost=@get_cfg_var("debugger.host")?yes:no;if ($debugerhost =="yes") {echo @get_cfg_var("debugger.port")?yes:no;}?></td>
</tr>
<tr>
 <td>smtp支持</td>
    <td><?php echo @get_cfg_var("smtp")?yes:no;?></td>
 <td>smtp地址</td>
    <td><?php echo @get_cfg_var("smtp");?></td>
</tr>
</table>
<?php
  break;
 case 'otherinfo': 
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">php组件支持状况</th>
</tr>
<tr>
 <td width="30%">拼写检查 aspell library</td>
    <td width="20%"><?php echo function_exists(aspell_new)?yes:no;?></td>
    <td width="30%">高精度数学运算 bcmath</td>
    <td><?php echo function_exists(bcadd)?yes:no;?></td>
</tr>
<tr>
 <td>历法运算 calendar</td>
    <td><?php echo function_exists(jdtofrench)?yes:no;?></td>
 <td>图形处理 gd library</td>
    <td><?php echo function_exists(imageline)?yes:no;?></td>
</tr>
<tr>
 <td>类/对象支持</td>
    <td><?php echo function_exists(class_exists)?yes:no;?></td>
 <td>字串类型检测支持</td>
    <td><?php echo function_exists(ctype_upper)?yes:no;?></td>
</tr>
<tr>
 <td>iconv编码支持</td>
    <td><?php echo function_exists(iconv)?yes:no;?></td>
 <td>mcrypt加密处理支持</td>
    <td><?php echo function_exists(mcrypt_cbc)?yes:no;?></td>
</tr>
<tr>
 <td>哈稀计算 mhash</td>
    <td><?php echo function_exists(mhash)?yes:no;?></td>
 <td>openssl支持</td>
    <td><?php echo function_exists(openssl_open)?yes:no;?></td>
</tr>
<tr>
 <td>prel相容语法 pcre</td>
    <td><?php echo function_exists(preg_match)?yes:no;?></td>
 <td>正则扩展(兼容perl)支持</td>
    <td><?php echo function_exists(preg_match)?yes:no;?></td>
</tr>
<tr>
 <td>socket支持</td>
    <td><?php echo function_exists(fsockopen)?yes:no;?></td>
 <td>流媒体支持</td>
    <td><?php echo function_exists(stream_context_create)?yes:no;?></td>
</tr>
<tr>
 <td>tokenizer支持</td>
    <td><?php echo function_exists(token_name)?yes:no;?></td>
 <td>url支持</td>
    <td><?php echo function_exists(parse_url)?yes:no;?></td>
</tr>
<tr>
 <td>wddx支持(web distributed data exchange)</td>
    <td><?php echo function_exists(wddx_add_vars)?yes:no;?></td>
 <td>压缩文件支持(zlib)</td>
    <td><?php echo function_exists(gzclose)?yes:no;?></td>
</tr>
<tr>
 <td>xml解析</td>
    <td><?php echo function_exists(xml_set_object)?yes:no;?></td>
 <td>ftp</td>
    <td><?php echo function_exists(ftp_login)?yes:no;?></td>
</tr>
<tr>
 <td>目录存取协议(ldap)支持</td>
    <td><?php echo function_exists(ldap_close)?yes:no;?></td>
 <td>yellow page系统支持</td>
    <td><?php echo function_exists(yp_match)?yes:no;?></td>
</tr>
<tr>
 <td>php和java综合支持</td>
    <td><?php echo function_exists(java_last_exception_get)?yes:no;?></td>
 <td>imap电子邮件系统支持</td>
    <td><?php echo function_exists(imap_close)?yes:no;?></td>
</tr>
<tr>
 <td>snmp网络管理协议支持</td>
    <td><?php echo function_exists(snmpget)?yes:no;?></td>
 <td>vmailmgr邮件处理支持</td>
    <td><?php echo function_exists(vm_adduser)?yes:no;?></td>
</tr>
<tr>
 <td>pdf文档支持</td>
    <td><?php echo function_exists(pdf_close)?yes:no;?></td>
 <td>fdf表单资料格式支持</td>
    <td><?php echo function_exists(fdf_close)?yes:no;?></td>
</tr>
</table>
<?php
  break;
 case 'dbinfo': 
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">数据库支持状况</th>
</tr>
<tr>
 <td width="30%">mysql数据库支持</td>
    <td width="20%"><?php echo function_exists(mysql_close)?yes:no;?></td>
 <td width="30%">mysql数据库持续连接</td>
    <td><?php echo @get_cfg_var("mysql.allow_persistent")?yes:no;?></td>
</tr>
<tr>
 <td>mysql最大连接数</td>
    <td><?php echo @get_cfg_var("mysql.max_links")==-1 ? "不限" : @get_cfg_var("mysql.max_links");?></td>
 <td>odbc数据库连接</td>
    <td><?php echo function_exists(odbc_close)?yes:no;?></td>
</tr>
<tr>
 <td>sql server数据库支持</td>
    <td><?php echo function_exists(mssql_close)?yes:no;?></td>
 <td>msql数据库支持</td>
    <td><?php echo function_exists(msql_close)?yes:no;?></td>
</tr>
<tr>
 <td>postgre sql数据库支持</td>
    <td><?php echo function_exists(pg_close)?yes:no;?></td>
 <td>oracle数据库支持</td>
    <td><?php echo function_exists(ora_close)?yes:no;?></td>
</tr>
<tr>
 <td>oracle 8 数据库支持</td>
    <td><?php echo function_exists(ocilogoff)?yes:no;?></td>
 <td>dbase数据库支持</td>
    <td><?php echo function_exists(dbase_close)?yes:no;?></td>
</tr>
<tr>
 <td>sybase数据库支持</td>
    <td><?php echo function_exists(sybase_close)?yes:no;?></td>
 <td>dba数据库支持</td>
    <td><?php echo function_exists(dba_close)?yes:no;?></td>
</tr>
<tr>
 <td>dbm数据库支持</td>
    <td><?php echo function_exists(dbmclose)?yes:no;?></td>
 <td>dbx数据库支持</td>
    <td><?php echo function_exists(dbx_close)?yes:no;?></td>
</tr>
<tr>
 <td>db++数据库支持</td>
    <td><?php echo function_exists(dbplus_close)?yes:no;?></td>
 <td>frontbase数据库支持</td>
    <td><?php echo function_exists(fbsql_close)?yes:no;?></td>
</tr>
<tr>
 <td>filepro数据库支持</td>
    <td><?php echo function_exists(filepro)?yes:no;?></td>
 <td>informix数据库支持</td>
    <td><?php echo function_exists(ifx_close)?yes:no;?></td>
</tr>
<tr>
 <td>lotus notes数据库支持</td>
    <td><?php echo function_exists(notes_version)?yes:no;?></td>
 <td>interbase数据库支持</td>
    <td><?php echo function_exists(ibase_close)?yes:no;?></td>
</tr>
<tr>
 <td>ingres数据库支持</td>
    <td><?php echo function_exists(ingres_close)?yes:no;?></td>
 <td>hyperwave数据库支持</td>
    <td><?php echo function_exists(hw_close)?yes:no;?></td>
</tr>
<tr>
 <td>ovrimos sql数据库连接支持</td>
    <td><?php echo function_exists(ovrimos_close)?yes:no;?></td>
 <td>sesam数据库连接支持</td>
    <td><?php echo function_exists(sesam_disconnect)?yes:no;?></td>
</tr>
<tr>
 <td>sqlite数据库连接支持</td>
    <td><?php echo function_exists(sqlite_close)?yes:no;?></td>
 <td>adabas d数据库连接支持</td>
    <td><?php echo function_exists(ada_close)?yes:no;?></td>
</tr>
</table>
<?php
  break;
 case 'testinfo': 
?>
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo1"?>" method="post">
<!--服务器性能检测-->
<div id="testinfo1">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr><th colspan="4">服务器性能检测</th></tr>
<tr align="center">
 <td width="25%">参照对象</td>
 <td width="25%">整数运算能力检测(1+1运算300万次)</td>
 <td width="25%">浮点运算能力检测(开平方300万次)</td>
 <td width="25%">数据i/o能力检测(读取10k文件1万次)</td>
</tr>
<tr align="center">
 <td>红色主机单线型(双核)</td>
 <td>0.33 秒</td>
 <td>0.95 秒</td>
 <td>0.03 秒</td>
</tr>
<tr align="center">
 <td>红色主机双线型(四核)</td>
 <td>0.25 秒</td>
 <td>0.79 秒</td>
 <td>0.03 秒</td>
</tr>
<tr align="center">
 <td>xeon(tm) 2.80*2+4g+centos 5.2</td>
 <td>0.068秒</td>
 <td>0.086秒</td>
 <td>小于0.100秒</td>
</tr>
<tr align="center">
 <td>xeon(tm) 2.80ghz+2g+freebsd 4.0</td>
 <td>0.501秒</td>
 <td>0.694秒</td>
 <td>小于0.100秒</td>
</tr>
<tr align="center" height="50">
 <td>本台服务器</td>
 <td><span style="color:#390"><?php echo $valint;?></span> <input type="submit" value="整型测试" name="act" class="button" /></td>
 <td><span style="color:#06c"><?php echo $valfloat;?></span> <input type="submit" value="浮点测试" name="act" class="button" /></td>
 <td><span style="color:#f60"><?php echo $valio;?></span> <input type="submit" value="io测试" name="act" class="button" /></td>
</tr>
</table>
</div>
<input type="hidden" name="pint" value="<?php echo $valint;?>" />
<input type="hidden" name="pfloat" value="<?php echo $valfloat;?>" />
<input type="hidden" name="pio" value="<?php echo $valio;?>" />
</form>
<?php
$ismysql = (false !== function_exists("mysql_query"))?"":" disabled";
$ismail = (false !== function_exists("mail"))?"":" disabled";
?>
<br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo2"?>" method="post">
<div id="testinfo2">
<!--mysql数据库连接检测--><br /><br />
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable2" align="center">
<tr><th colspan="2">mysql数据库连接检测</th></tr>
<tr>
 <td width="30%" align="right">mysql服务器:</td>
 <td><input name="mysqlhost" type="text" id="mysqlhost" value="localhost" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql用户名:</td>
 <td><input name="mysqluser" type="text" id="mysqluser" value="root" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql用户密码:</td>
 <td><input type="text" name="mysqlpassword" <?php echo $ismysql?> size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql数据库名称:</td>
 <td><input type="text" name="mysqldb" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right" height="30"><input type="submit" class="button" value="connect" <?php echo $ismysql?>  name="act" /></td>
    <td><div class="check00"><?php if("show"==$mysqlreshow){echo $mysqlre;}?> </div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo5"?>" method="post">
<div id="testinfo5">
<!--邮件发送检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable3" align="center">
<tr><th colspan="2">php配置参数状况</th></tr>
<tr>
    <td width="30%" align="right">请输入您要检测的参数名称:</td>
    <td><input type="text" name="opname" size="80" class="text2" /></td>
</tr>
<tr>
    <td align="right" height="30"><input type="submit" class="button" value="configuration_check" name="act" /></td>
    <td><div class="check00"><?php if("show"==$opreshow){echo $opre;}?></div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo3"?>" method="post">
<div id="testinfo3">
<!--函数检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable4" align="center">
<tr><th colspan="2">函数检测</th></tr>
<tr>
 <td width="30%" align="right">请输入您要检测的函数名称:</td>
 <td><input type="text" name="funname" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right" height="30"><input type="submit" class="button" value="function_check" name="act" /></td>
    <td><div class="check00"><?php if("show"==$funreshow){echo $funre;}?> </div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo4"?>" method="post">
<div id="testinfo4">
<!--邮件发送检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable5" align="center">
<tr><th colspan="2">mail邮件发送测试</th></tr>
<tr>
    <td width="30%" align="right">请输入您要检测的邮件地址:</td>
    <td><input type="text" name="mailreceiver" size="80" <?php echo $ismail?> class="text2" /></td>
</tr>
<tr>
    <td align="right" height="30"><input type="submit" class="button" value="sendmail" <?php echo $ismail?>  name="act" /></td>
    <td><div class="check00"><?php if("show"==$mailreshow){echo $mailre;}?></div></td>
</tr>
</table>
</div>
</form>

<?php
  break;
}?>
</div>

</div>
</body>
</html>
<?php

/*=============================================================
    函数库
=============================================================*/

/*-------------------------------------------------------------------------------------------------------------
    检测函数支持
--------------------------------------------------------------------------------------------------------------*/
    function isfun($funname)
    {
        return (false !== function_exists($funname))?yes:no;
    }
/*-------------------------------------------------------------------------------------------------------------
    检测php设置参数
--------------------------------------------------------------------------------------------------------------*/
    function getcon($varname)
    {
        switch($res = get_cfg_var($varname))
        {
            case 0:
            return no;
            break;
            case 1:
            return yes;
            break;
            default:
            return $res;
            break;
        }
        
    }
/*-------------------------------------------------------------------------------------------------------------
    整数运算能力测试
--------------------------------------------------------------------------------------------------------------*/
    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, 6)."秒";
        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, 6)."秒";
        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, 6)."秒";
        return($time);
    }
/*-------------------------------------------------------------------------------------------------------------
    比例条
--------------------------------------------------------------------------------------------------------------*/
    function bar($percent)
    {
    echo '<br/><ul class="bar">
 <li style="width:';
 echo $percent."%">";
    echo '&nbsp;</li>
    </ul>';
}
/*-------------------------------------------------------------------------------------------------------------
    根据不同系统取得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("/models+names{0,}:+s{0,}([ws)(.]+)[ ]+/", $str, $model);
        //@preg_match_all("/cpus+mhzs{0,}:+s{0,}([d.]+)[ ]+/", $str, $mhz);
        @preg_match_all("/caches+sizes{0,}:+s{0,}([d.]+s{0,}[a-z]+[ ]+)/", $str, $cache);
        if (false !== is_array($model[1]))
            {
            $res['cpu']['num'] = sizeof($model[1]);
            for($i = 0; $i < $res['cpu']['num']; $i++)
            {
                $res['cpu']['detail'][] = "类型:".$model[1][$i]." 缓存:".$cache[1][$i];
            }
            if (false !== is_array($res['cpu']['detail'])) $res['cpu']['detail'] = implode("<br />", $res['cpu']['detail']);
            }
        
        // 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("/memtotals{0,}:+s{0,}([d.]+).+?memfrees{0,}:+s{0,}([d.]+).+?swaptotals{0,}:+s{0,}([d.]+).+?swapfrees{0,}:+s{0,}([d.]+)/s", $str, $buf);
        
        $res['memtotal'] = round($buf[1][0]/1024, 2);
        $res['memfree'] = round($buf[2][0]/1024, 2);
        $res['memused'] = ($res['memtotal']-$res['memfree']);
        $res['mempercent'] = (floatval($res['memtotal'])!=0)?round($res['memused']/$res['memtotal']*100,2):0;
        
        $res['swaptotal'] = round($buf[3][0]/1024, 2);
        $res['swapfree'] = round($buf[4][0]/1024, 2);
        $res['swapused'] = ($res['swaptotal']-$res['swapfree']);
        $res['swappercent'] = (floatval($res['swaptotal'])!=0)?round($res['swapused']/$res['swaptotal']*100,2):0;
        
        // load avg
        if (false === ($str = @file("/proc/loadavg"))) return false;
        $str = explode(" ", implode("", $str));
        $str = array_chunk($str, 3);
        $res['loadavg'] = implode(" ", $str[0]);
        
        return $res;
    }
/*-------------------------------------------------------------------------------------------------------------
    系统参数探测 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function sys_freebsd()
    {
        //cpu
        if (false === ($res['cpu']['num'] = get_key("hw.ncpu"))) return false;
        $res['cpu']['detail'] = get_key("hw.model");
        
        //load avg
        if (false === ($res['loadavg'] = get_key("vm.loadavg"))) return false;
        $res['loadavg'] = str_replace("{", "", $res['loadavg']);
        $res['loadavg'] = str_replace("}", "", $res['loadavg']);
        
        //uptime
        if (false === ($buf = get_key("kern.boottime"))) return false;
        $buf = explode(' ', $buf);
        $sys_ticks = time() - intval($buf[3]);
        $min = $sys_ticks / 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 === ($buf = get_key("hw.physmem"))) return false;
        $res['memtotal'] = round($buf/1024/1024, 2);
        $buf = explode(" ", do_command("vmstat", ""));
        $buf = explode(" ", trim($buf[2]));
        
        $res['memfree'] = round($buf[5]/1024, 2);
        $res['memused'] = ($res['memtotal']-$res['memfree']);
        $res['mempercent'] = (floatval($res['memtotal'])!=0)?round($res['memused']/$res['memtotal']*100,2):0;
          
        $buf = explode(" ", do_command("swapinfo", "-k"));
        $buf = $buf[1];
        preg_match_all("/([0-9]+)s+([0-9]+)s+([0-9]+)/", $buf, $bufarr);
        $res['swaptotal'] = round($bufarr[1][0]/1024, 2);
        $res['swapused'] = round($bufarr[2][0]/1024, 2);
        $res['swapfree'] = round($bufarr[3][0]/1024, 2);
        $res['swappercent'] = (floatval($res['swaptotal'])!=0)?round($res['swapused']/$res['swaptotal']*100,2):0;
        
        return $res;
    }
    
/*-------------------------------------------------------------------------------------------------------------
    取得参数值 freebsd
--------------------------------------------------------------------------------------------------------------*/
function get_key($keyname)
    {
        return do_command('sysctl', "-n $keyname");
    }
    
/*-------------------------------------------------------------------------------------------------------------
    确定执行文件位置 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function find_command($commandname)
    {
        $path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
        foreach($path as $p)
        {
            if (@is_executable("$p/$commandname")) return "$p/$commandname";
        }
        return false;
    }
    
/*-------------------------------------------------------------------------------------------------------------
    执行系统命令 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function do_command($commandname, $args)
    {
        $buffer = "";
        if (false === ($command = find_command($commandname))) return false;
        if ($fp = @popen("$command $args", 'r'))
            {
    while (!@feof($fp))
    {
     $buffer .= @fgets($fp, 4096);
    }
    return trim($buffer);
   }
        return false;
    }

/*-------------------------------------------------------------------------------------------------------------
    系统参数探测 windows
--------------------------------------------------------------------------------------------------------------*/
    function sys_windows()
 {
 //$phpos=php_os;
 $sysinfo['uptime'] ="对不起windows系统不支持";
 
 }
?>

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • 解决Pycharm的项目目录突然消失的问题

    今天小编就为大家分享一篇解决Pycharm的项目目录突然消失的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-04-22
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • C#路径,文件,目录及IO常见操作汇总

    这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • PHP函数strip_tags的一个bug浅析

    PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
  • PHP加密解密函数详解

    分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。 加密代码如下: /* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand(...2015-10-30
  • SQL Server中row_number函数的常见用法示例详解

    这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • docker 启动elasticsearch镜像,挂载目录后报错的解决

    这篇文章主要介绍了docker 启动 elasticsearch镜像,挂载目录后报错的解决,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-20
  • php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法

    最近遇到一个问题,就是在使用php的mail函数发送utf-8编码的中文邮件时标题出现乱码现象,而邮件正文却是正确的。最初以为是页面编码的问题,发现页面编码utf-8没有问题啊,找了半天原因,最后找到了问题所在。 1.使用 PEAR 的...2015-10-21