//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