Why is the PHP Curl post mode sending data slow? I'll tell you why.

Source: Internet
Author: User

Case:

Today to upload a file to a server, the original is Curl's get mode, now use the post mode, according to the original thought, the code is as follows

1<?PHP2 $post[' c '] = ' config ';3 $post[' t '] = ' show ';4 $post[' o '] = ' xml ';5 $post[' ssid '] = '%07o%b4%88o%ee%0ca%07%da%d8i%d36he%af%28%bc%3c%be%d5s%dfv%a6%d83%d9%3e%16%96u%b4q%ba%0a%9a%de%f0% Bfjjh%df2%ff%d2 ';6 7 8 $curl=curl_init ();9curl_setopt ($curl, Curlopt_url, "http://172.16.59.130:28099/cgi-bin/japi.cgi");Tencurl_setopt ($curl, Curlopt_post,true); Onecurl_setopt ($curl, Curlopt_postfields,$post); Acurl_setopt ($curl, curlopt_encoding, "gzip"); -curl_setopt ($curl, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/38.0.2125.111 safari/537.36 -Accept-encoding:gzip,deflate,sdch "); the  -curl_setopt ($curl, Curlopt_returntransfer, 1); -curl_setopt ($curl, Curlinfo_header_out,true); -curl_setopt ($curl, Curlopt_followlocation,false); + $contents= Curl_exec ($curl); -Curl_close ($curl); + Echo $contents; A?>

But time is always around 2s, and with Get mode is very quickly, just start to suspect is the server problem, but with a try attitude, check the next Curl post what special place, this really found.

In PHP Curl post mode, when enabled, a regular post request is sent with the type:application/x-www-form-urlencoded, just like the form submitted.

If you convert the array you want to post to a string, like get that URL, the speed comes up.

1<?PHP2 $post[' c '] = ' config ';3 $post[' t '] = ' show ';4 $post[' o '] = ' xml ';5 6 $post=Http_build_query($post);7 $post. = "&ssid=%07o%b4%88o%ee%0ca%07%da%d8i%d36he%af%28%bc%3c%be%d5s%dfv%a6%d83%d9%3e%16%96u%b4q%ba%0a%9a%de%f0% Bfjjh%df2%ff%d2 ";8 9 $curl=curl_init ();Tencurl_setopt ($curl, Curlopt_url, "http://172.16.59.130:28099/cgi-bin/japi.cgi"); Onecurl_setopt ($curl, Curlopt_post,true); Acurl_setopt ($curl, Curlopt_postfields,$post); -curl_setopt ($curl, curlopt_encoding, "gzip"); -curl_setopt ($curl, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/38.0.2125.111 safari/537.36 theAccept-encoding:gzip,deflate,sdch "); -  -curl_setopt ($curl, Curlopt_returntransfer, 1); -curl_setopt ($curl, Curlinfo_header_out,true); +curl_setopt ($curl, Curlopt_followlocation,false); - $contents= Curl_exec ($curl); +Curl_close ($curl); A Echo $contents; at?>

Why is the PHP Curl post mode sending data slow? I'll tell you why.

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.