4

I dont understand the PHP cURL function curl_multi_exec().

int curl_multi_exec(handle h, int running)

I went through the PHP manual http://www.php.net but don't understand what the variable running does.

Searched a lot on Google but didn't find the explanation. Can somebody explain?

Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
lovesh
  • 5,235
  • 9
  • 62
  • 93

1 Answers1

4

Every time you call it, that variable is assigned to tell you whether the op is still running:

curl_multi_exec($ch, $running);

After that, $running is non-zero if the operations are still running. If so, you will have to call it again (normally in a loop).

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • does this operation takes too long? why do i need to put in a loop? – lovesh Apr 07 '11 at 17:15
  • 3
    @lovesh, yes, `curl_multi_exec` is commonly used when you're running multiple curl jobs in parallel. They can take a while to finish, so you call `curl_multi_exec` repeatedly so curl can update you with the status. You can also call [`curl_multi_select`](http://www.php.net/manual/en/function.curl-multi-select.php) if you want to block until one of the requests has made progress. – Matthew Flaschen Apr 07 '11 at 17:29
  • It doesn't just tell you if there are operations running, it reports the number of operations which are currently active (not completed). And you should have a blocking call to sleep()/usleep() or curl_multi_select() inside the same loop to avoid slowing your system down too much. – symcbean Mar 02 '15 at 15:16