Home >Backend Development >PHP Tutorial > PHP cURL并发里的callback那行是什么效能
PHP cURL并发里的callback那行是什么功能?
function rolling_curl($urls, $delay) {<br> $queue = curl_multi_init();<br> $map = array();<br> <br> foreach ($urls as $url) {<br> $ch = curl_init();<br> <br> curl_setopt($ch, CURLOPT_URL, $url);<br> curl_setopt($ch, CURLOPT_TIMEOUT, 1);<br> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br> curl_setopt($ch, CURLOPT_HEADER, 0);<br> curl_setopt($ch, CURLOPT_NOSIGNAL, true);<br> <br> curl_multi_add_handle($queue, $ch);<br> $map[(string) $ch] = $url;<br> }<br> <br> $responses = array();<br> do {<br> while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM) ;<br> <br> if ($code != CURLM_OK) { break; }<br> <br> // a request was just completed -- find out which one<br> while ($done = curl_multi_info_read($queue)) {<br> <br> // get the info and content returned on the request<br> $info = curl_getinfo($done['handle']);<br> $error = curl_error($done['handle']);<br> $results = callback(curl_multi_getcontent($done['handle']), $delay);<br> $responses[$map[(string) $done['handle']]] = compact('info', 'error', 'results');<br> <br> // remove the curl handle that just completed<br> curl_multi_remove_handle($queue, $done['handle']);<br> curl_close($done['handle']); <div class="clear"> </div>