按手册上说,这两个函数的唯一区别是,pfsockopen是持续连接,而fsockopen不是.
我写了个代码了一下:
复制代码 代码如下:
$data=1,0,721,73,1,0,0,43290000,0,60d81d509bc00451,3,ffffffff;
//http://10.144.99.114/sanex_new/modules/subscribemanager/test.php
$host = '127.0.0.1';
$url = /aa.php;
$pffirst = false;
$times = 1000;
$starttime = microtime(true);
for ($index = 0; $index echo httppost($host,$url,$data,$pffirst).
;
}
$middletime = microtime(true);
for ($index = 0; $index echo httppost($host,$url,$data,!$pffirst).
;;
}
$endtime = microtime(true);
echo ($pffirst?pfsocket:fsocket).:.($middletime-$starttime);
echo
;
echo ($pffirst?fsocket:pfsocket).:.($endtime-$middletime);
$count=0;
//发包函数
function httppost($host,$url,$data,$p)
{
global $count;
$func = $p?pfsockopen:fsockopen;
$conn = $func($host,80,$errno, $errstr, 30);
if (!$conn)
{
echo $errstr ($errno)
\n;
return;
}
$header = post .$url. http/1.1\r\n;
$header.= host : {$host}\r\n;
$header.= content-type: application/x-www-form-urlencoded\r\n;
$header.= content-length:.strlen($data).\r\n;
$header.= connection: keep-alive\r\n\r\n;
$header.= {$data}\r\n\r\n;
fwrite($conn,$header);
$count++;
echo $count.' '.$header.
;
$resp='';
//while (!feof($conn)) {
// $resp .= fgets($conn);
/