提高php程序性能和负载测试

 更新时间:2016年11月25日 16:24  点击:1862
一篇关于提高php程序性能和负载测试的实例代码,有需要的朋友可以看看如何提高自己程序的性能哦。

计算执行的时间
通过下面这个简单的方法可以计算一段程序的执行时间(微妙)

 代码如下 复制代码

$start_time = microtime(true);

//一些需要计算时间的代码
//... code here ...

print('代码的运行时间是:'.getExecTime($start_time));

function getExecTime($start_time)
{
 return microtime(true)-$start_time;
}PEAR的Benchmark模块提供了更详细的时间统计功能

require_once 'Benchmark/Timer.php';
$timer =& new Benchmark_Timer(true);
$timer->start();
// 设置函数
$timer->setMarker('setup');
// some more code executed here
$timer->setMarker('middle');
// even yet still more code here
$timer->setmarker('done');
// and a last bit of code here
$timer->stop();
$timer->display();通过declare结构和ticks指令可以实现自动记录每一行PHP代码执行的时间

// A function that records the time when it is called
function profile($dump = FALSE)
{
    static $profile;

    // Return the times stored in profile, then erase it
    if ($dump) {
        $temp = $profile;
        unset($profile);
        return ($temp);
    }

    $profile[] = microtime();
}

// Set up a tick handler
register_tick_function("profile");

// Initialize the function before the declare block
profile();

// Run a block of code, throw a tick every 2nd statement
declare(ticks=2) {
    for ($x = 1; $x < 50; ++$x) {
        echo similar_text(md5($x), md5($x*$x)), ";";
    }
}

// Display the data stored in the profiler
print_r(profile (TRUE));注意:ticks 指令在 PHP 5.3.0 中是过时指令,将会从 PHP 6.0.0 移除。

代码排错
主要介绍的是Advanced PHP Debugger(APD),通过设置可以生成跟踪文件,对文件进行分析可以得到脚本的详细信息

网站压力测试
人们常混淆压力测试和基准测试。基准测试是一种由单独的开发者完成的临时活动,常用Apache HTTP测试工具——ab,该工具可以测试一台HTTP服务器每秒能相应的请求数。压力测试是一种能中断你WEB应用程序的测试技术,通过对断点测试,能识别并修复应用程序中的弱点,为何时购置新硬件提供依据。常用的开源工具是Siege。

提速技巧
通过安装PHP加速器可以有效的提供PHP的执行速度,常见的三种加速器是Alternative PHP Cache(APC)、eAccelerator和ionCube PHP Accelerator(PHPA)。另外需要注意的是加速器的兼容性通常会滞后于新发布的PHP版本。

另外提速技巧是在能不使用正则的时候尽量不要用,通常可替代的方案会比使用正则效率更高。

生成饼图很多代码都可以实现,今天我们介绍的这个实例是基于php gd库的一种生成统计数据的饼图效果,有需要的同学可以参考一下。
 代码如下 复制代码
<?
//+------------------------+
//| pie3dfun.PHP//公用函数 |
//+------------------------+
define("ANGLE_STEP", 5); //定义画椭圆弧时的角度步长
function draw_getdarkcolor($img,$clr) //求$clr对应的暗色
{
$rgb = imagecolorsforindex($img,$clr);
return array($rgb["red"]/2,$rgb["green"]/2,$rgb["blue"]/2);
}
function draw_getexy($a, $b, $d) //求角度$d对应的椭圆上的点坐标
{
$d = deg2rad($d);
return array(round($a*Cos($d)), round($b*Sin($d)));
}
function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) //椭圆弧函数
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a,$b,$d);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
}
function draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr) //画扇面
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr);
list($x, $y) = draw_getexy($a/2, $b/2, ($d+$sd)/2);
imagefill($img, $x+$ox, $y+$oy, $clr);
}
function draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clr) //3d扇面
{
draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr);
if($sd<180)
{
list($R, $G, $B) = draw_getdarkcolor($img, $clr);
$clr=imagecolorallocate($img, $R, $G, $B);
if($ed>180) $ed = 180;
list($sx, $sy) = draw_getexy($a,$b,$sd);
$sx += $ox;
$sy += $oy;
list($ex, $ey) = draw_getexy($a, $b, $ed);
$ex += $ox;
$ey += $oy;
imageline($img, $sx, $sy, $sx, $sy+$v, $clr);
imageline($img, $ex, $ey, $ex, $ey+$v, $clr);
draw_arc($img, $ox, $oy+$v, $a, $b, $sd, $ed, $clr);
list($sx, $sy) = draw_getexy($a, $b, ($sd+$ed)/2);
$sy += $oy+$v/2;
$sx += $ox;
imagefill($img, $sx, $sy, $clr);
}
}
function draw_getindexcolor($img, $clr) //RBG转索引色
{
$R = ($clr>>16) & 0xff;
$G = ($clr>>8)& 0xff;
$B = ($clr) & 0xff;
return imagecolorallocate($img, $R, $G, $B);
}
// 绘图主函数,并输出图片
// $datLst 为数据数组, $datLst 为标签数组, $datLst 为颜色数组
// 以上三个数组的维数应该相等
function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10)
{
$ox = 5+$a;
$oy = 5+$b;
$fw = imagefontwidth($font);
$fh = imagefontheight($font);
$n = count($datLst);//数据项个数
$w = 10+$a*2;
$h = 10+$b*2+$v+($fh+2)*$n;
$img = imagecreate($w, $h);
//转RGB为索引色
for($i=0; $i<$n; $i++)
$clrLst[$i] = draw_getindexcolor($img,$clrLst[$i]);
$clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff);
$clrt = imagecolorallocate($img, 0x00, 0x00, 0x00);
//填充背景色
imagefill($img, 0, 0, $clrbk);
//求和
$tot = 0;
for($i=0; $i<$n; $i++)
$tot += $datLst[$i];
$sd = 0;
$ed = 0; 333
$ly = 10+$b*2+$v;
for($i=0; $i<$n; $i++)
{
$sd = $ed;
$ed += $datLst[$i]/$tot*360;
//画圆饼
draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i]);
//画标签
imagefilledrectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrLst[$i]);
imagerectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrt);
//imagestring($img, $font, 5+2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)", $clrt);
$str = iconv("GB2312", "UTF-8", $labLst[$i]);
ImageTTFText($img, $font, 0, 5+2*$fw, $ly+13, $clrt, "./simsun.ttf", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
$ly += $fh+2;
}
//输出图形
header("Content-type: image/png");
//输出生成的图片
$imgFileName = "../temp/".time().".png";
imagepng($img,$imgFileName);
echo '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
$datLst = array(30, 10, 20, 20, 10, 20, 10, 20); //数据
$labLst = array("中国科技大学", "安徽理工大学", "清华大学", "北京大学", "南京大学", "上海大学", "河海大学", "中山大学"); //标签
$clrLst = array(0x99ff00, 0xff6666, 0x0099ff, 0xff99ff, 0xffff99, 0x99ffff, 0xff3333, 0x009999);
//画图
draw_img($datLst,$labLst,$clrLst);
?>

效果图如下

要实现记住密码自动登录的功能我们大多数据都是利用了客户端的cookies来实现,我们利用php也不例外,有需要的朋友可以参考一下。

php制作记住密码自动登录的解决思路,其实也就是对session,cookies的操作
//检查用户是否登录 

 代码如下 复制代码
function checklogin(){ 
     if(empty($_SESSION['user_info'])){    //检查一下session是不是为空 
     if(empty($_COOKIE['username']) || empty($_COOKIE['password'])){  //如果session为空,并且用户没有选择记录登录状 
     header("location:login.php?req_url=".$_SERVER['REQUEST_URI']);  //转到登录页面,记录请求的url,登录后跳转过去,用户体验好。 
}else{   //用户选择了记住登录状态 
     $user = getUserInfo($_COOKIE['username'],$_COOKIE['password']);   //去取用户的个人资料 
     if(empty($user)){    //用户名密码不对没到取到信息,转到登录页面 
     header("location:login.php?req_url=".$_SERVER['REQUEST_URI']); 
     }else{ 
     $_SESSION['user_info'] = $user;   //用户名和密码对了,把用户的个人资料放到session里面 
     } 
     } 
     } 
}


二,用户提交登录信息

 代码如下 复制代码
username = trim($_POST['username']); 
$password = md5(trim($_POST['password'])); 
$validatecode = $_POST['validateCode']; 
$ref_url = $_GET['req_url']; 
$remember = $_POST['remember']; 
 
$err_msg = ''; 
if($validatecode!=$_SESSION['checksum']){ 
$err_msg = "验证码不正确"; 
}elseif($username=='' || $password==''){ 
$err_msg = "用户名和密码都不能为空"; 
}else{ 
$row = getUserInfo($username,$password); 
 
if(empty($row)){ 
$err_msg = "用户名和密码都不正确"; 
}else{ 
$_SESSION['user_info'] = $row; 
if(!empty($remember)){     //如果用户选择了,记录登录状态就把用户名和加了密的密码放到cookie里面 
setcookie("username", $username, time()+3600*24*365); 
setcookie("password", $password, time()+3600*24*365); 

if(strpos($ref_url,"login.php") === false){ 
header("location:".$ref_url); 
}else{ 
header("location:main_user.php"); 


}


三,当用户点退出时,清出记录登录状态


//退出登录 

 代码如下 复制代码
function logout(){ 
unset($_SESSION['user_info']); 
if(!empty($_COOKIE['username']) || !empty($_COOKIE['password'])){ 
setcookie("username", null, time()-3600*24*365); 
setcookie("password", null, time()-3600*24*365); 

}
分享一个网友写的php图片上传类,支持加水印,生成略缩图功能哦,面是配置和可以获取的一些信息(每一个配置信息都有默认值,如无特殊需要,可以不配置):
 代码如下 复制代码

<?php
/*----------------------------------------------------------------------------------
 *
 *----------------------------------------------------------------------------------
 */
class image_up{
 //定义基本参数
 private $uptype=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png');  //上传文件类型
 private $max_file_size=102400;    //上传大小限制(单位:KB)
 private $destination_folder="up/"; //上传文件路径
 private $watermark=1;              //是否附加水印
 private $watertype=1;              //水印类型(1为文字,2为图片)
 private $waterposition=1;          //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);
 private $waterstring=null;         //水印字符串
 private $waterimg=null;            //水印图片
 private $imgpreview=1;             //是否生成预览图(1为生成,其他为不生成);
 private $imgpreviewsize=1;         //预览图比例,0为按固定宽和高显示,其他为比例显示
 private $imgwidth=200;             //预览图固定宽度
 private $imgheight=200;            //预览图固定高度
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 private $imgthu=1;                     //是否生成且保存略缩图,1为生成,0为不生成
 private $imgthu_folder=null;           //略缩图保存路径,默认与文件路径一致
 private $imgthu_fixed=0;               //略缩图是否使用固定宽高,1为使用,0为灵活变动
 private $imgthu_width=200;             //略缩图宽度
 private $imgthu_height=200;            //略缩图高度
 
 private $imgthu_name=null;             //略缩图名称
 //******************************************************************************************************************
 private $inputname="upfile";       //文件上传框名称
 //******************************************************************************************************************
 private $img_preview_display;      //图片预览图显示
 //******************************************************************************************************************
 //文件上传相关信息,1为文件不存在,2为类型不符合,3为超出大小限制,4为上传失败,0为上传成功
 private $file_up_info=null;
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 //可在外部获取上传文件基本信息
 private $file_name;         //客服端文件的原名称
 private $file_type;         //文件的MIME类型
 private $file_size;         //已上传文件的大小,单位/字节
 private $file_tmp_name;     //储存的临时文件名
 private $file_error;        //该文件上传相关错误代码

 private $img_size;          //取得图片的长宽
 private $file_basename;     //获取带扩展名的全名
 private $file_extension;    //获取文件扩展名
 private $filename;          //文件名(不带扩展名)
 private $destination;       //问价路径加名称
 //******************************************************************************************************************
 public function __set($propety_name,$value){
  $this->$propety_name=$value;
 }
 public function __get($property_name){
  if(isset($this->$property_name))
  return($this->$property_name);
  else return(NULL);
 }
 //******************************************************************************************************************
 //定义文件上传功能
 public function up(){
  //判断文件是否存在
  if(!is_uploaded_file($_FILES[$this->inputname]["tmp_name"])){
   $this->file_up_info=1;
   return;
  }
  //获取并赋值相应基本参数
  $upfile=$_FILES[$this->inputname];
  $this->file_name=$upfile["name"];
  $this->file_type=$upfile["type"];
  $this->file_size=$upfile["size"];
  $this->file_tmp_name=$upfile["tmp_name"];
  $this->file_error=$upfile["error"];
  //检查文件类型是否符合
  if(!in_array($this->file_type,$this->uptype)){
   $this->file_up_info=2;
   return;
  }
  //检查文件大小是否超出限制
  if($this->file_size>$this->max_file_size){
   $this->file_up_info=3;
   return;
  }
  //判断目录是否存在
  if(!file_exists($this->destination_folder))
  mkdir($this->destination_folder);
  //进一步取得图片的信息并赋值
  $this->img_size=getimagesize($this->file_tmp_name);
  $pathinfo=pathinfo($this->file_name);
  $this->file_extension=$pathinfo["extension"];    //获取文件扩展名
  $this->file_basename=$pathinfo["basename"];      //获取带扩展名的全名
  $this->filename=$pathinfo["filename"];           //文件名(不带扩展名)
  $filename2=$pathinfo['filename'];
  $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
  //判断文件名是否存在,如果存在则重命名
  $n=1;
  while (file_exists($this->destination)){
   while (file_exists($this->destination)){
    $n++;
    $this->filename=$this->filename."(".$n.")";
    $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
   }
   $this->filename=$filename2."(".$n.")";
   $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
  }
  //移动上传的文件
  if(move_uploaded_file($this->file_tmp_name,$this->destination))
  $this->file_up_info=0;
  else $this->file_up_info=4;
   
  //添加水印
  if($this->watermark==1){
   $this->imgthu();
  }
  //生成略缩图
  if($this->imgthu==1){
   $this->add_watermark();
  }
  //生成预览图
  if($this->imgpreviewsize == 0){
   if($this->img_size["0"]<$this->imgwidth) $this->imgwidth=$this->img_size["0"];
   if($this->img_size["1"]<$this->imgheight) $this->imgheight=$this->img_size["1"];
  }else{
   $this->imgwidth=$this->img_size["0"]*$this->imgpreviewsize;
   $this->imgheight=$this->img_size["1"]*$this->imgpreviewsize;
  }
  $this->img_preview_display="<img src='$this->destination' width='$this->imgwidth' height='$this->imgheight'
                                    alt='图片预览:r文件名':$this->file_tmp_name />";
 }
//====================================================================================================================
//==================================================================================================================== 
 //生成略缩图功能
 function imgthu(){
  if($this->imgthu_folder==null)
    $this->imgthu_folder=$this->destination_folder;
  
  //$this->imgthu_name=$this->filename."_t.".$this->file_extension;
  $imgthu_name_b=$this->filename."_t";
  $imgthu_name_b2=$this->filename."_t";
  $destination_b=$this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
     //判断文件名是否存在,如果存在则重命名
  $n=1;
  while (file_exists($destination_b)){
   while (file_exists($destination_b)){
    $n++;
    $imgthu_name_b=$imgthu_name_b."(".$n.")";
    $destination_b = $this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
   }
   $imgthu_name_b=$imgthu_name_b2."(".$n.")";
   $destination_b = $this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
  }
  
  
  $imginfo=getimagesize($this->destination);
  switch($imginfo[2])
  {
   case 1:
    $in=@imagecreatefromgif($this->destination);
    break;
   case 2:
    $in=@imagecreatefromjpeg($this->destination);
    break;
   case 3:
    $in=@imagecreatefrompng($this->destination);
    break;
   case 6:
    $in =@imagecreatefrombmp($this->destination);
    break;
   default:
    break;
  }
  //计算略缩图长宽
  if($this->imgthu_fixed==0){
   if($this->imgthu_height>($imginfo[1]/$imginfo[0])*$this->imgthu_width)
    $this->imgthu_width = ($imginfo[0]/$imginfo[1])*$this->imgthu_height;
   else
    $this->imgthu_height=($imginfo[1]/$imginfo[0])*$this->imgthu_width;
  }
  $new = imageCreateTrueColor($this->imgthu_width,$this->imgthu_height);
  ImageCopyResized($new,$in,0,0,0,0,$this->imgthu_width,$this->imgthu_height,$imginfo[0],$imginfo[1]);
  switch ($imginfo[2])
  {
   case 1:
    imagejpeg($new,$destination_b);
    break;
   case 2:
    imagejpeg($new,$destination_b);
    break;
   case 3:
    imagepng($new,$destination_b);
    break;
   case 6:
    imagewbmp($new,$destination_b);
    break;
  }
 }
//====================================================================================================================
//==================================================================================================================== 
 //添加水印功能
 function add_watermark(){
  //1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),
  //8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
  $imginfo=getimagesize($this->destination);
  $im=imagecreatetruecolor($this->img_size[0],$this->img_size[1]);       //创建真彩色
  $white=imagecolorallocate($im,255,255,255);                            //设置颜色
  $black=imagecolorallocate($im,0,0,0);
  $red=imagecolorallocate($im,255,0,0);
  //在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。
  imagefill($im,0,0,$white);

  switch($imginfo[2])
  {
   case 1:
    $simage =imagecreatefromgif($this->destination);      // 创建一个新的形象,从文件或 URL
    break;
   case 2:
    $simage =imagecreatefromjpeg($this->destination);
    break;
   case 3:
    $simage =imagecreatefrompng($this->destination);
    break;
   case 6:
    $simage =imagecreatefromwbmp($this->destination);
    break;
   default:
    echo ("不支持的文件类型");
    break;
  }
  if(!empty($simage))
  {
   //位置设置
   if($this->watertype==1){
    $str_len=strlen($this->waterstring);
       $str_width=$str_len*10;
       $str_height=20;
   }elseif($this->watertype==1 && file_exists($this->waterimg)){
    $iinfo=getimagesize($this->waterimg);
    $str_width = $iinfo[0];
    $str_height = $iinfo[1];
   }
   
   switch ($this->waterposition){
    case 1:
     $p_x=5;
     $p_y=$this->img_size[1]-$str_height;
     break;
    case 2:
     $p_x=$this->img_size[0]-$str_width;
     $p_y=$this->img_size[1]-$str_height;
     break;
    case 3:
     $p_x=5;
     $p_y=0;
     break;
    case 4:
     $p_x=$this->img_size[0]-$str_width;
     $p_y=5;
     break;
    case 5:
     $p_x=($this->img_size[0]-$str_width)/2;
     $p_y=($this->img_size[1]-$str_height)/2;
     break;
   }
   imagecopy($im,$simage,0,0,0,0,$this->img_size[0],$this->img_size[1]);   //拷贝图像的一部分
   //imagefilledrectangle($im,1,$this->img_size[1]-15,130,$this->img_size[1],$white);  //将图片的封闭长方形区域着色

   switch($this->watertype)
   {
    case 1:   //加水印字符串
     imagestring($im,10,$p_x,$p_y,$this->waterstring,$red);
     break;
    case 2:   //加水印图片
     $simage1 =imagecreatefromgif($this->waterimg);
     imagecopy($im,$simage1,0,0,0,0,85,15);
     imagedestroy($simage1);
     break;
   }

   switch ($imginfo[2])
   {
    case 1:
     //imagegif($nimage, $destination);
     imagejpeg($im, $this->destination);
     break;
    case 2:
     imagejpeg($im, $this->destination);
     break;
    case 3:
     imagepng($im, $this->destination);
     break;
    case 6:
     imagewbmp($im, $this->destination);
     break;
   }
   //覆盖原上传文件
   imagedestroy($im);
   imagedestroy($simage);
  }
 }
}
?>

在php中用来操作远程图片的方法有很多,本文章只讲到简单的一个curl就可以实现了,如果各位想深入了解,模仿用户的话可以参考我们网站其它方法。
 代码如下 复制代码


<?php
$url = "http://www.111cn.net/img/logo.jpg";
$filename = 'curl.gif';

getImg($url, $filename);
/*
*@通过curl方式获取制定的图片到本地
*@ 完整的图片地址
*@ 要存储的文件名
*/
function getImg($url = "", $filename = "") {
if(is_dir(basename($filename))) {
echo "The Dir was not exits";
Return false;
}
//去除URL连接上面可能的引号
$url = preg_replace( '/(?:^['"]+|['"/]+$)/', '', $url );
$hander = curl_init();
$fp = fopen($filename,'wb');
curl_setopt($hander,CURLOPT_URL,$url);
curl_setopt($hander,CURLOPT_FILE,$fp);
curl_setopt($hander,CURLOPT_HEADER,0);
curl_setopt($hander,CURLOPT_FOLLOWLOCATION,1);
//curl_setopt($hander,CURLOPT_RETURNTRANSFER,false);//以数据流的方式返回数据,当为false是直接显示出来
curl_setopt($hander,CURLOPT_TIMEOUT,60);
/*$options = array(
CURLOPT_URL=> 'http://www.111cn.net/img/logo.jpg',
CURLOPT_FILE => $fp,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60
);
curl_setopt_array($hander, $options);
*/
curl_exec($hander);
curl_close($hander);
fclose($fp);
Return true;
}
?>

[!--infotagslink--]

相关文章

  • 解决@SpringBootTest 单元测试遇到的坑

    这篇文章主要介绍了解决@SpringBootTest 单元测试遇到的坑,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-10-14
  • DWVA上传漏洞挖掘的测试例子

    DVWA (Dam Vulnerable Web Application)DVWA是用PHP+Mysql编写的一套用于常规WEB漏洞教学和检测的WEB脆弱性测试程序。包含了SQL注入、XSS、盲注等常见的一些安全漏洞...2016-11-25
  • PHP测试成功的邮件发送案例

    mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
  • 用VirtualBox构建MySQL测试环境

    宿主机使用网线的时候,客户机在Bridged Adapter模式下,使用Atheros AR8131 PCI-E Gigabit Ethernet Controller上网没问题。 宿主机使用无线的时候,客户机在Bridged Adapter模式下,使用可选项里唯一一个WIFI选项,Microsoft Virtual Wifi Miniport Adapter也无法上网,故弃之。...2013-09-19
  • 带你了解PHP7 性能翻倍的关键

    20岁老牌网页程序语言PHP,最快将在10月底释出PHP 7新版,这是十年来的首次大改版,最大特色是在性能上的大突破,能比前一版PHP 5快上一倍,PHP之父Rasmus Lerdorf表示,甚至能比HHVM虚拟机下的PHP程序性能更快。HHVM 是脸书为自...2015-11-24
  • 利用 Chrome Dev Tools 进行页面性能分析的步骤说明(前端性能优化)

    这篇文章主要介绍了利用 Chrome Dev Tools 进行页面性能分析的步骤说明(前端性能优化),本文给大家介绍的非常想详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-02-24
  • JavaScript提高网站性能优化的建议(二)

    这篇文章主要介绍了JavaScript提高网站性能优化的建议(二)的相关资料,需要的朋友可以参考下...2016-07-29
  • 提升jQuery的性能需要做好七件事

    这篇文章主要介绍了提升jQuery的性能需要做好的七件事,希望真的帮助大家提升jQuery性能,需要的朋友可以参考下...2016-01-14
  • PHP测试成功的邮件发送案例

    mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
  • php测试性能代码

    php测试性能代码 function microtime_float () { list ($usec, $sec) = explode(" ", microtime()); return ((float) $usec + (float) $sec); } functio...2016-11-25
  • phpmyadmin写入一句话木马的测试

    下面我们一起来看看一篇关于phpmyadmin写入一句话木马的测试教程,希望此教程能够对各位有帮助。 方法一,一句话木马偶尔拿到一个config中,发现是root,且还有phpmyadmi...2016-11-25
  • css中空路径对页面性能影响的解决方案

    文章介绍了css中空路径对页面性能影响的解决方案,这个可能很多美工朋友不会去注意这一点,下面我们来看看吧。 在写 CSS 的时候,用 background:url(#) 还是会对页面进...2017-07-06
  • 如何用Node.js编写内存效率高的应用程序

    这篇文章主要介绍了如何用Node.js编写内存效率高的应用程序,对Node.js感兴趣的同学,可以参考下...2021-05-01
  • python自动化测试selenium执行js脚本实现示例

    这篇文章主要为大家介绍了python自动化测试selenium执行js脚本的实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步...2021-11-13
  • Redis 执行性能测试

    这篇文章主要介绍了Redis 执行性能测试的方法,文中讲解非常细致,帮助大家更好的理解和学习redis,感兴趣的朋友可以了解下...2021-01-15
  • 详解Nginx服务器中配置Sysguard模块预防高负载的方案

    这篇文章主要介绍了详解Nginx服务器中配置Sysguard模块预防高负载的方案,该模块由阿里巴巴的团队开发,能够设置负载阀值,比较强大,需要的朋友可以参考下...2016-02-02
  • js简单网速测试方法完整实例

    这篇文章主要介绍了js简单网速测试方法,以完整实例形式分析了JavaScript基于网页图片下载进行测试网速的实现技巧,需要的朋友可以参考下...2015-12-17
  • 浅析Mysql Join语法以及性能优化

    一.Join语法概述join 用于多表中字段之间的联系,语法如下:复制代码 代码如下:... FROM table1 INNER|LEFT|RIGHT JOIN table2 ON conditionatable1:左表;table2:右表。JOIN 按照功能大致分为如下三类:INNER JOIN(内连接,或...2014-05-31
  • JavaWeb实战之编写单元测试类测试数据库操作

    这篇文章主要介绍了JavaWeb实战之编写单元测试类测试数据库操作,文中有非常详细的代码示例,对正在学习javaweb的小伙伴们有很大的帮助,需要的朋友可以参考下...2021-04-22
  • Springboot 使用具体化类和配置来缩短单元测试时间

    这篇文章主要介绍了Springboot 使用具体化类和配置来缩短单元测试时间,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-11-05