Home > Backend Development > PHP Tutorial > PHP cURL并发里的callback那行是什么效能

PHP cURL并发里的callback那行是什么效能

WBOY
Release: 2016-06-13 12:37:34
Original
967 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template