深入解析fsockopen與pfsockopen的區(qū)別_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:使用PHP實(shí)現(xiàn)蜘蛛訪問日志統(tǒng)計(jì)本篇文章是對(duì)使用PHP實(shí)現(xiàn)蜘蛛訪問日志統(tǒng)計(jì)的代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下: $useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT'])); if (strpos($useragent, 'googlebot')!== false){$bot = 'Google';} elseif (strpos($u
按手冊(cè)上說,這兩個(gè)函數(shù)的唯一區(qū)別是,pfsockopen是持續(xù)連接,而fsockopen不是.
我寫了個(gè)代碼了一下:
<?php
$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 < $times; $index++) {
echo httpPost($host,$url,$data,$pffirst)."<hr><br />";
}
$middleTime = microtime(true);
for ($index = 0; $index < $times; $index++) {
echo httpPost($host,$url,$data,!$pffirst)."<hr><br />";;
}
$endTime = microtime(true);
echo ($pffirst?"pfsocket":"fsocket").":".($middleTime-$startTime);
echo "<br />";
echo ($pffirst?"fsocket":"pfsocket").":".($endTime-$middleTime);
$count=0;
//發(fā)包函數(shù)
function httpPost($host,$url,$data,$p)
{
global $count;
$func = $p?"pfsockopen":"fsockopen";
$conn = $func($host,80,$errno, $errstr, 30);
if (!$conn)
{
echo "$errstr ($errno)<br />\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."<br /><br />";
$resp='';
//while (!feof($conn)) {
// $resp .= fgets($conn);
/
分享:如何解決CI框架的Disallowed Key Characters錯(cuò)誤提示用CI框架時(shí),有時(shí)候會(huì)遇到這么一個(gè)問題,打開網(wǎng)頁,只顯示 Disallowed Key Characters 錯(cuò)誤提示。有人說 url 里有非法字符。但是確定 url 是純英文的,問題還是出來了。但清空瀏覽器歷史記錄和cookies后。 刷新就沒問題了。有時(shí)候。打開不同的瀏覽器。有的瀏覽器會(huì)有問
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- PHPMailer郵件發(fā)送的實(shí)現(xiàn)代碼
- 基于在生產(chǎn)環(huán)境中使用php性能測(cè)試工具xhprof的詳解
- 淺談PHP5 OOP編程之代理與定制異常(2)
- 小結(jié):PHP動(dòng)態(tài)網(wǎng)頁程序優(yōu)化及高效提速問題
- php獲取$_POST同名參數(shù)數(shù)組的實(shí)現(xiàn)介紹
- PHP實(shí)用:用PHP來實(shí)現(xiàn)圖片的簡(jiǎn)單上傳
- PHP初學(xué):實(shí)例詳細(xì)學(xué)習(xí)PHP的簡(jiǎn)單語法
- 十天學(xué)會(huì)php之第十天
- php類:注冊(cè)與自動(dòng)加載
- 使用php+apc實(shí)現(xiàn)上傳進(jìn)度條且在IE7下不顯示的問題解決方法
- 相關(guān)鏈接:
- 教程說明:
PHP教程-深入解析fsockopen與pfsockopen的區(qū)別
。