


php curl 中的gzip压缩性能测试
添加时间:2014-9-23 17:04:03
添加:
思海网络
前因:
1
请求端口次数很多,每日两亿多次,主要是有些端口返回数据量很大高达110KB(为了减少请求次数,将多个端口合并成一个导致的)。后端端口的nginx已经开启gzip,所以做个测试,看看是否在请求时使用压缩解压
php CURL 的扩展安装这里就不说了
用到的curl的两个参数
//在http 请求头加入 gzip压缩<br>curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
//curl返回的结果,采用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";
测试结果 请求100次平均耗时 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";
测试结果 请求100次平均耗时 2.6s 0.026/次
结果:
1、不使用压缩比使用压缩 请求一次快 5ms
2、千兆网,在局域网内传输这些数据大概是 0.7ms
关键字:gzip、压缩、数据
新文章:
- CentOS7下图形配置网络的方法
- CentOS 7如何添加删除用户
- 如何解决centos7双系统后丢失windows启动项
- CentOS单网卡如何批量添加不同IP段
- CentOS下iconv命令的介绍
- Centos7 SSH密钥登陆及密码密钥双重验证详解
- CentOS 7.1添加删除用户的方法
- CentOS查找/扫描局域网打印机IP讲解
- CentOS7使用hostapd实现无AP模式的详解
- su命令不能切换root的解决方法
- 解决VMware下CentOS7网络重启出错
- 解决Centos7双系统后丢失windows启动项
- CentOS下如何避免文件覆盖
- CentOS7和CentOS6系统有什么不同呢
- Centos 6.6默认iptable规则详解