深入解析fsockopen与pfsockopen的区别_PHP
程序员文章站
2024-01-31 18:27:40
...
按手册上说,这两个函数的唯一区别是,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);
/
我写了个代码了一下:
复制代码 代码如下:
$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);
/
推荐阅读
-
深入解析fsockopen与pfsockopen的区别_PHP
-
深入理解ob_flush和flush的区别(ob_flush()与flush()使用方法)_PHP教程
-
深入理解ob_flush和flush的区别(ob_flush()与flush()使用方法)_PHP
-
解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别_PHP教程
-
深入解析fsockopen与pfsockopen的区别
-
深入eAccelerator与memcached的区别详解_php技巧
-
解析php addslashes()与add*es()函数的区别和比较_PHP教程
-
PHP中mb_convert_encoding与iconv函数的深入解析
-
PHP中mb_convert_encoding与iconv函数的深入解析_PHP
-
解析isset与is_null的区别_PHP