Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check progress of cURL

Tags:

php

curl

Is there some way to check the status of a curl command? Say, I have a call to curl from php, using exec to initiate it. Is there a way I can check the progress of it while it's running? Or do I have to wait for it to finish?

exec("curl $url -k > /dev/null 2>&1 &");

like image 410
Nathan Avatar asked Oct 11 '22 17:10

Nathan


1 Answers

You can define a progress function:

curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, 'my_progress_handler');

The name of a callback function where the callback function takes three parameters. The first is the cURL resource, the second is a file-descriptor resource, and the third is length. Return the string containing the data.

For further information, see here.

Attention: This comment disputes PHP's own function signature.

You cannot use exec(), because it is a blocking function. It will wait, until the program at hand has terminated.
Edit: Oh, I see that you have used the ampersand, nevermind

What you could use is popen(), but unless curl has a nice way of outputting the progress, this isn't going to be pretty.

I would suggest passing -# as parameter to curl, that way you can grab the progress nicely off the output stream.

like image 101
phant0m Avatar answered Oct 18 '22 11:10

phant0m