diff --git a/examples/multi_curl_add_curl_from_url_list.php b/examples/multi_curl_add_curl_from_url_list.php new file mode 100644 index 0000000..24eebfc --- /dev/null +++ b/examples/multi_curl_add_curl_from_url_list.php @@ -0,0 +1,41 @@ +complete(function ($instance) use (&$multi_curl, &$urls) { + echo 'complete:' . $instance->url . "\n"; + + // Queue another request each time a request completes. Fetch the oldest url + // next using array_shift($urls) or use the most recently added url using + // array_pop($urls). + // $next_url = array_shift($urls); + // $next_url = array_pop($urls); + $next_url = array_shift($urls); + + if ($next_url !== null) { + $multi_curl->addGet($next_url); + } +}); + +// Queue a few requests. +$concurrency = 3; +for ($i = 0; $i < $concurrency; $i++) { + $next_url = array_shift($urls); + if ($next_url !== null) { + $multi_curl->addGet($next_url); + } +} + +$multi_curl->start();