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.