PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php curl批处理实现可控并发异步操作示例大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP curl批处理实现可控并发异步操作。分享给大家供大家参,具体如下:

通常情况下 PHP 中的 cURL 是阻塞运行的,就是说创建一个 cURL 请求以后必须等它执行成功或者超时才会执行下一个请求:API接口访问一般会首选CURL

在实际项目或者自己编写小工具(比如新闻聚合,商品价格监控,比价)的过程中,通常需要从第3方网站或者API接口获取数据,在需要处理1个URL队列时,为了提高性能,可以采用cURL提供的curl_multi_*函数实现简单的并发.

php;">
<>PHP
include 'curl.class.PHP';
function callBACk($response,$info,$error,$request)
{
 echo 'response:
'; print_r($responsE); echo '
' . date("Y-m-d H:i:s") . '
'; echo '
' . str_repeat("-",100) . '
'; } $user_COOKIE = (!empty($_requEST['cookie'])) ? $_requEST['cookie'] : file_get_contents("cookie.txt"); $curl = new Curl ("callBACk"); $data = array( array( 'url' => 'http://dyactive2.vip.xunlei.com/com_sign/?game=qmr&type=rec_gametime&referfrom=&rt=0.42521539455332336',//秦美人 'method' => 'POST','post_data' => '','header' => null,'options' => array( CURLOPT_REFERER => "http://niu.xunlei.com/entergame/?gameNo=qmr&fenQuNum=3",CURLOPT_COOKIE => $user_COOKIE,) ),array( 'url' => 'http://dyactive2.vip.xunlei.com/com_sign/?game=sq&type=rec_gametime&referfrom=&rt=0.42521539455332336',//神曲 'method' => 'POST','options' => array( CURLOPT_REFERER => "http://niu.xunlei.com/entergame/?gameNo=sq&fenQuNum=41",array( 'url' => 'http://dyactive2.vip.xunlei.com/com_sign/?game=frxz&type=rec_gametime&referfrom=&rt=0.42521539455332336',//凡人修真 'method' => 'POST','options' => array( CURLOPT_REFERER => "http://niu.xunlei.com/entergame/?gameNo=frxz&fenQuNum=3",array( 'url' => 'http://dyactive2.vip.xunlei.com/com_sign/?game=smxj&type=rec_gametime&referfrom=&rt=0.42521539455332336',//神魔仙界 'method' => 'POST','options' => array( CURLOPT_REFERER => "http://niu.xunlei.com/entergame/?gameNo=smxj&fenQuNum=2",array( 'url' => 'http://dyactive2.vip.xunlei.com/com_sign/?game=qsqy&type=rec_gametime&referfrom=&rt=0.42521539455332336',//倾世情缘 'method' => 'POST','options' => array( CURLOPT_REFERER => "http://niu.xunlei.com/entergame/?gameNo=qsqy&fenQuNum=11",); foreach ($data as $val) { $request = new Curl_request ($val ['url'],$val ['method'],$val ['post_data'],$val ['header'],$val ['options']); $curl->add($request); } $curl->execute(); echo $curl->display_errors();

大佬总结

以上是大佬教程为你收集整理的php curl批处理实现可控并发异步操作示例全部内容,希望文章能够帮你解决php curl批处理实现可控并发异步操作示例所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。