Analysis of gzip compression performance test instances in php curl, curlgzip

Source: Internet
Author: User

Analysis of gzip compression performance test instances in php curl, curlgzip

This article analyzes the gzip compression performance test in php curl. We will share this with you for your reference. The details are as follows:

Cause:

The number of request interfaces is large, with more than 0.2 billion requests per day. This is mainly because some interfaces return a large amount of data up to KB (which is caused by merging multiple interfaces into one to reduce the number of requests ).

The nginx of the backend interface has enabled gzip, so perform a test to check whether compression and decompression are used in the request.

Php CURL extension installation is not mentioned here

The two curl parameters used

// Add gzip compression curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('Accept-Encoding: gzip') to the http request header; // The result returned by curl, use gzip to decompress curl_setopt ($ ch, CURLOPT_ENCODING, "gzip ");

1. Do not use compression for decompression

$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";

Test results:

The average time for 100 requests is 2.1 s, 0.021 s/Time

2. Use compression to decompress

$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";

Test results:

The average time consumption for 100 requests is 2.6 s and 0.026/Time

Result Analysis:

1. A compression request is faster than 5 ms without a compression ratio

2. The data transmitted over the LAN over a gigabit network is about 0.7 ms.

Conclusion:

Currently, curl compression and decompression are not used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.