php curl 中的gzip压缩性能测试

php CURL 的扩展安装这里就不说了

用到的curl的两个参数

1
2
3
4
//在http 请求头加入 gzip压缩
curl_setopt( $ch , CURLOPT_HTTPHEADER, array ( 'Accept-Encoding:gzip' ));
//curl返回的结果,采用gzip解压
curl_setopt( $ch , CURLOPT_ENCODING, "gzip" );

 

1、不使用压缩解压

1
2
3
4
5
6
7
8
9
10
11
12
$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、使用压缩解压

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$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
2
1、不使用压缩比使用压缩 请求一次快 5ms
2、千兆网,在局域网内传输这些数据大概是 0.7ms

 

结论

暂时不使用 curl 的压缩和解压

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值