tags:

views:

79

answers:

2

What does this do?

$running = null;
{
  curl_multi_exec($mh,$running);
  usleep(100000);          
} while ($running > 0); 

Also:

curl_setopt($ch, CURLOPT_TIMEOUT, 8); 

Its PHP and curl.

A: 

So, if I understand what curl_multi_exec does, it seems this code is running the curl multi-handler, $mh every 100000 microseconds (100 milliseconds or 0.1 seconds) to see if it's done.

curl_setopt($ch, CURLOPT_TIMEOUT, 8); tells curl to timeout after 8 seconds.

Rocket
+1  A: 

curl_multi_exec is used to process multiple curl handles in parellel. For example, it might be used to download multiple web pages in parallel. This is more efficient than processing the handles in sequence.

The code is kicking of the processing of multiple curl handles. It is checking back every 1/10th of a second to see if all handles have been processed. The second parameter to curl_multi_exec is a flag to say whether the operations are still running. This value is checked to determine whether to keep looping.

The CURLOPT_TIMEOUT setting is used to specify a maximum time to allow a curl handle to process. The code is setting a maximum time of 8 seconds.

Stephen Curran