In this paper, we analyze the compression performance test of gzip in PHP curl. Share to everyone for your reference, specific as follows:
Antecedent:
Request interface A lot of times, 200 million times a day, mainly some interfaces to return data large up to 110KB (in order to reduce the number of requests, the combination of multiple interfaces into one result).
The nginx of the backend interface is already turned on gzip, so do a test to see if you want to use compression decompression on request
Extended installation of PHP CURL here's the word.
Two parameters of the curl used
In the HTTP request header, add gzip compression
curl_setopt ($ch, Curlopt_httpheader, Array (' Accept-encoding:gzip '));
Curl returns the results, using gzip decompression
curl_setopt ($ch, curlopt_encoding, "gzip");
1, do not use compression decompression
$s 1 = 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)-$s 1;
echo "\ n";
Test results:
Request 100 times Average time consuming 2.1s 0.021s/times
2, use compression decompression
$s 1 = 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)-$s 1;
echo "\ n";
Test results:
Request 100 times Average time consuming 2.6s 0.026/Time
Results Analysis:
1, do not use compression than the use of compression request a fast 5ms
2, gigabit Network, in the LAN transmission of these data is probably 0.7ms
Conclusion:
Temporarily do not use curl compression and decompression
More about PHP Interested readers can view the site topics: "Php Curl Usage Summary", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", " PHP Programming algorithm Summary, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.