troubleshooting Question

Need help on multi_curl

Avatar of lovewithu
lovewithu asked on
PHP
8 Comments1 Solution419 ViewsLast Modified:

I got a php script that is using multi_curl where I would need a little help on. It´s nothing big but I don´t find the solution

So here is the part of the script that is making problems:
$ch = array();
$master = curl_multi_init();

for($i = 0; $i < 5; $i++)
{
$ch[$i] = curl_init();
curl_setopt($ch[$i], CURLOPT_URL, $url[$i]);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$i], CURLOPT_HEADER, 1);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, cTimeout);

curl_multi_add_handle($master, $ch[$i]);
}

do
{
unset ($curlInfo);

curl_multi_exec($master,$running);

$curlInfo = curl_multi_info_read ($master);

// I guess if curlInfo[msg] == 1 that means that one of the handles finished
if ($curlInfo[msg] == 1)
{

/////////////////////////////////////////////////////////////////////////////// HERE IS THE PROBLEM
}
} while($running > 0);

Now if you take a look at "HERE IS THE PROBLEM". I need to know instantly when the handle´s transfer has finished to know which of the 5 handles has finished.

So I tried looping all handles using curl_getinfo but the problem there is that until the loop has finished already other handles have finished so that I only can find out e.g. handle 1,2 and 5 have finished but I don´t get the information instantly as soon as a handle has finished.

But enough of that - I guess more explanation is more confusing to my bad English.

All that I need is the exact Syntax how I would find out in a curl_multi_exec IF and WHICH handle has finished. So probably 2 lines of code.
So here is the part of the script that is making problems:
$ch = array();
$master = curl_multi_init();
 
for($i = 0; $i < 5; $i++)
{
$ch[$i] = curl_init();
curl_setopt($ch[$i], CURLOPT_URL, $url[$i]);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$i], CURLOPT_HEADER, 1);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, cTimeout);
 
curl_multi_add_handle($master, $ch[$i]);
}
 
do
{
unset ($curlInfo);
 
curl_multi_exec($master,$running);
 
$curlInfo = curl_multi_info_read ($master);
 
// I guess if curlInfo[msg] == 1 that means that one of the handles finished
if ($curlInfo[msg] == 1)
{
 
/////////////////////////////////////////////////////////////////////////////// HERE IS THE PROBLEM
}
} while($running > 0);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros