Antecedent: 1 Request interface many times daily, 200 million times a day, mainly some interface return data volume is large up to 110KB (in order to reduce the number of requests, the combination of multiple interfaces into one result). <br> back-end interface Nginx has been opened gzip, so do a test to see if the request to use compression decompression PHP CURL extension Installation Here is not said used in the CURL two parameters //Add gzip compression <br>curl_setopt ($ch, Curlopt_httpheader, Array (' Accept-encoding:gzip ') to the HTTP request header); Curl returns the result, using gzip decompression <br>curl_setopt ($ch, curlopt_encoding, "<span style=" line-height:1.5; " >gzip</span> "); 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 Requests 100 times average time 2.1s 0.021s/times 2, using 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 Requests 100 times average Time 2.6s 0.026/times result 1, no compression than using compression request one faster 5ms 2, gigabit Network, in LAN incoming This data is probably 0.7ms
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