469,950 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Cannot understand this libcurl script, any help?

I do not understand the sample code on php.net for curl_multi_exec.
Any help? Many thanks!

<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$running=null;
//execute the handles
do {
curl_multi_exec($mh,$running);
} while ($running 0);
//close the handles
curl_multi_remove_handle($ch1);
curl_multi_remove_handle($ch2);
curl_multi_close($mh);

?>

Question 1:

What does $running mean? $running is NULL at first, how it becomes a
value which is greater than zero?

Question 2:

For the User Contributed Notes (the other script on that page):

do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active and $mrc == CURLM_OK) {
// wait for network
if (curl_multi_select($mh) != -1) {
// pull in any new data, or at least handle timeouts
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}

What the hell $active is? No this declaration at all!

By the way, why there is no explanation of libcurl's pre-defined
constants? It is a nightmare to guess the real meaning of all those
constants!

Thanks!

Jul 1 '07 #1
2 1232
Ming wrote:
do {
curl_multi_exec($mh,$running);
} while ($running 0);
[...]
What does $running mean? $running is NULL at first,
No. It's undeclared at first.
how it becomes a value which is greater than zero?
http://www.php.net/manual/en/functio...multi-exec.php

"A reference to a flag to tell whether the operations are still running."

Now, re-read your programming books, looking for anything
on "pass-by-reference parameters". That should clear your mind.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

This virus requieres Microsoft Windows 3.x.
Jul 1 '07 #2
Iván Sánchez Ortega wrote:
Ming wrote:
>do {
curl_multi_exec($mh,$running);
} while ($running 0);
[...]
>What does $running mean? $running is NULL at first,

No. It's undeclared at first.
>how it becomes a value which is greater than zero?

http://www.php.net/manual/en/functio...multi-exec.php

"A reference to a flag to tell whether the operations are still running."

Now, re-read your programming books, looking for anything
on "pass-by-reference parameters". That should clear your mind.
No, $running is null. When you edited the post, you dropped:

$running=null;

As for how it changes - $running is passed by reference. This means if
curl_multi_exec changes the value of $running, the real value of
$running (not a copy) will change, and you will be able to test it in
your do...while loop.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sylvain/11XX | last post: by
reply views Thread by Raj | last post: by
reply views Thread by Raj | last post: by
1 post views Thread by Uday | last post: by
4 posts views Thread by Choi | last post: by
3 posts views Thread by Jake | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.