Cause: 1: The number of request interfaces is large, and the number of requests is more than 0.2 billion per day. this is mainly because some interfaces return a large amount of data up to KB (to reduce the number of requests, merge multiple interfaces into one ). & Lt; br & gt; nginx of the backend interface has enabled gzip, so let's test whether compression is used in the request... "/> <scripttype =" text/javascript "src =" h prefix: 1. many request interfaces, more than 0.2 billion times a day, it is mainly because some interfaces return a large amount of data up to KB (to reduce the number of requests, multiple interfaces are merged into one ).
The nginx of the backend interface has enabled gzip, so let's test it, check whether the extension of php CURL is compressed and decompressed during the request. here we will not talk about the two parameters of the curl used. // add gzip compression to the http request header.
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('Accept-Encoding: gzip '); // the results returned by curl are decompressed using gzip.
Curl_setopt ($ ch, CURLOPT_ENCODING, "gzip"); 1. extract data without compression $ 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 result request 100 average time consumption 2.1 s 0.021 s/Time 2. decompress with compression $ 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, hour, 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: 100 requests took an average time of 2.6 s 0.026/time. Result 1. if the compression ratio is not used, the request is faster than 0.7 ms at a time. the data transmitted over the LAN is about ms.
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.