jutmal Posted September 2, 2013 Share Posted September 2, 2013 (edited) Hello I am looking at creating a function for multiple post request to be send to server the code i have written is as follows function retrieve($urls) { $mh = curl_multi_init(); foreach($urls as $i => $url) { $ch[$i] = curl_init($url); curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1); curl_multi_add_handle($mh, $ch[$i]); } // Start performing the request do { $execReturnValue = curl_multi_exec($mh, $runningHandles); } while ($execReturnValue == CURLM_CALL_MULTI_PERFORM); // Loop and continue processing the request while ($runningHandles && $execReturnValue == CURLM_OK) { // Wait forever for network $numberReady = curl_multi_select($mh); if ($numberReady != -1) { // Pull in any new data, or at least handle timeouts do { $execReturnValue = curl_multi_exec($mh, $runningHandles); } while ($execReturnValue == CURLM_CALL_MULTI_PERFORM); } } // Check for any errors if ($execReturnValue != CURLM_OK) { trigger_error("Curl multi read error $execReturnValue\n", E_USER_WARNING); } // Extract the content foreach($urls as $i => $url) { // Check for errors $curlError = curl_error($ch[$i]); if($curlError == "") { $res[$i] = curl_multi_getcontent($ch[$i]); } else { print "Curl error on handle $i: $curlError\n"; } // Remove and close the handle curl_multi_remove_handle($mh, $ch[$i]); curl_close($ch[$i]); } // Clean up the curl_multi handle curl_multi_close($mh); // Print the response data print_r($res); } When i pass the urls array to it in the format $urls = array([0]=>http://xyz.com/request.php?name=xyz&pass=xyz$something=something,[1]=>http://xyz.com/request.php?name=xyz&pass=xyz$something=something); nothign happedn and its goes into a loop please help Edited September 5, 2013 by Maq Quote Link to comment https://forums.phpfreaks.com/topic/281776-curl_multi_exec-need-to-create-function-to-execute-for-post-details-to-website/ Share on other sites More sharing options...
Maq Posted September 5, 2013 Share Posted September 5, 2013 Don't double post, I deleted your other topic. Use code tags. Quote Link to comment https://forums.phpfreaks.com/topic/281776-curl_multi_exec-need-to-create-function-to-execute-for-post-details-to-website/#findComment-1448338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.