forms - PHP : Multiple cURL with same URL
Get the solution ↓↓↓Solution:
Your loop over the multi-handles doesn't appear complete. A more robust implementation:
function multiread($mh, $timeout = .5) {
$output = array ();
$runCnt = 0;
do {
// start requests, or update status of pending requests: returns by
// reference (in $runCnt) the number of outstanding requests
$status = curl_multi_exec($mh, $runCnt);
if (CURLM_OK !== $status) throw new \RuntimeException;
// take a breath, so as to not eat 100% CPU
do {
$status = curl_multi_select($mh, $timeout);
if (-1 === $status) {
usleep(10);
}
} while (0 === $status);
// gather the results and yield back what we know
while (false !== ($info = curl_multi_info_read($mh))) {
if (CURLE_OK === $info['result']) {
$output[] = [ $info, curl_multi_getcontent($info['handle']) ];
} else {
$output[] = [ $info, null ];
}
}
} while (0 < $runCnt);
return $output;
}
Now do some looping:
$mh = curl_multi_init();
// ... add your easy handles
foreach (multiread($mh) as list ($info, $content)) {
// $info['handle'] contains the cURL easy handle
// $info['result'] contains the result code, see also curl_strerror
// $content contains whatever the URL returned
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.