


php curl 中的gzip壓縮性能測(cè)試
添加時(shí)間:2014-9-23 17:04:03
添加:
思海網(wǎng)絡(luò)
前因:
1
請(qǐng)求端口次數(shù)很多,每日兩億多次,主要是有些端口返回?cái)?shù)據(jù)量很大高達(dá)110KB(為了減少請(qǐng)求次數(shù),將多個(gè)端口合并成一個(gè)導(dǎo)致的)。后端端口的nginx已經(jīng)開啟gzip,所以做個(gè)測(cè)試,看看是否在請(qǐng)求時(shí)使用壓縮解壓
php CURL 的擴(kuò)展安裝這里就不說了
用到的curl的兩個(gè)參數(shù)
//在http 請(qǐng)求頭加入 gzip壓縮<br>curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
//curl返回的結(jié)果,采用gzip解壓<br>curl_setopt($ch, CURLOPT_ENCODING, "<span style="line-height: 1.5;">gzip</span>");
1、不使用壓縮解壓
$s1 = microtime(true);
$ch = curl_init();
for($i=0; $i<100;$i++){
$url="http://192.168.0.11:8080/xxxxx/xxxxx?";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$data = curl_exec($ch);
}
curl_close($ch);
echo microtime(true)-$s1;
echo "\n";
測(cè)試結(jié)果 請(qǐng)求100次平均耗時(shí) 2.1s 0.021s/次
2、使用壓縮解壓
$s1 = microtime(true);
$ch = curl_init();
for($i=0; $i<100;$i++){
$url="http://192.168.0.1:8080/xxxxx/xxxxx?";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
$data = curl_exec($ch);
}
curl_close($ch);
echo microtime(true)-$s1;
echo "\n";
測(cè)試結(jié)果 請(qǐng)求100次平均耗時(shí) 2.6s 0.026/次
結(jié)果:
1、不使用壓縮比使用壓縮 請(qǐng)求一次快 5ms
2、千兆網(wǎng),在局域網(wǎng)內(nèi)傳輸這些數(shù)據(jù)大概是 0.7ms
關(guān)鍵字:gzip、壓縮、數(shù)據(jù)
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解