Curl sends multiple requests at the same time

Source: Internet
Author: User

//Create a pair of curl resources$ch 1=curl_init ();$ch 2=curl_init ();//set the URL and the appropriate optionscurl_setopt ($ch 1, Curlopt_url, "http://test.cm/a.php/"); curl_setopt ($ch 1, Curlopt_header, 0); curl_setopt ($ch 1, Curlopt_returntransfer, 1); curl_setopt ($ch 2, Curlopt_url, "http://testd.cm/b.php"); curl_setopt ($ch 2, Curlopt_header, 0); curl_setopt ($ch 2, Curlopt_returntransfer, 1 );//Create a batch curl handle$MH=curl_multi_init ();//Add 2 handlesCurl_multi_add_handle ($MH,$ch 1); Curl_multi_add_handle ($MH,$ch 2);$running=NULL;//executing a batch handle Do {    //handle all requests and know that all is doneCurl_multi_exec ($MH,$running);}  while($running> 0);//gets the returned content for each request based on the handle$a= Curl_multi_getcontent ($ch 1); EE ($a); EE (Curl_error ($ch 1));//An error in a single request does not affect other requests$b= Curl_multi_getcontent ($ch 2); EE ($b);//Close all handlesCurl_multi_remove_handle ($MH,$ch 1); Curl_multi_remove_handle ($MH,$ch 2); Curl_multi_close ($MH);

Curl sends multiple requests at the same time

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.