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

php中文网
发布: 2016-06-23 14:22:15
原创
1339人浏览过

curl cURL php 并发  curlcURL php 并发  curl cURL 并发

function rolling_curl($urls, $delay) {    $queue = curl_multi_init();    $map = array();     foreach ($urls as $url) {        $ch = curl_init();         curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_TIMEOUT, 1);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($ch, CURLOPT_HEADER, 0);        curl_setopt($ch, CURLOPT_NOSIGNAL, true);         curl_multi_add_handle($queue, $ch);        $map[(string) $ch] = $url;    }     $responses = array();    do {        while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM) ;         if ($code != CURLM_OK) { break; }         // a request was just completed -- find out which one        while ($done = curl_multi_info_read($queue)) {             // get the info and content returned on the request            $info = curl_getinfo($done['handle']);            $error = curl_error($done['handle']);            $results = callback(curl_multi_getcontent($done['handle']), $delay);            $responses[$map[(string) $done['handle']]] = compact('info', 'error', 'results');             // remove the curl handle that just completed            curl_multi_remove_handle($queue, $done['handle']);            curl_close($done['handle']);        }         // Block for data in / output; error handling is done by curl_multi_exec        if ($active > 0) {            curl_multi_select($queue, 0.5);        }     } while ($active);     curl_multi_close($queue);    return $responses;}
登录后复制


也就是第三十行是什么功能?
curl_multi_getcontent($done['handle'])我知道,后面那个参数有什么作用?

回复讨论(解决方案)

你看看自定义函数 callback 的定义不就知道了吗?
$delay 是你传入的,并传递给 callback 的,意义当然只有你知道

嗯 查看一下 callback 这个函数的代码写的是什么 要是看不懂可以发上来

你看看自定义函数 callback 的定义不就知道了吗?
$delay 是你传入的,并传递给 callback 的,意义当然只有你知道

嗯 查看一下 callback 这个函数的代码写的是什么 要是看不懂可以发上来

找到了。。。原来是...原来是测试性能的。。。

function callback($data, $delay) {    preg_match_all('/<h3>(.+)<\/h3>/iU', $data, $matches);    usleep($delay);    return compact('data', 'matches');}
登录后复制


唉。。。这就是自己看文章不完整引起的。。。
嗯,谢谢两位版主的提醒~~~

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号