dongqiancui9194 2017-06-26 20:32
浏览 55
已采纳

什么是add_url_multi_handle()?

I can't find it in any docs and it doesn't come up when I search for it. I'm trying to follow this tutorial, here's my code so far:

$location_urls = array();

foreach($entity_ids as $url) {

    array_push($location_urls, 'https://something.com/api/v1/location/' . $url);

}

$mh = curl_multi_init();

for ($i = 0; $i < count($entity_ids); $i++) {

    add_url_to_multi_handle($mh, $location_urls);

}

here's the error i'm getting:

<b>Fatal error</b>:  Uncaught Error: Call to undefined function add_url_to_multi_handle() in C:\xampp\htdocs\api_test\example.php:45
Stack trace:
#0 {main}
thrown in <b>C:\xampp\htdocs\api_test\example.php</b> on line <b>45</b><br />

and nothing comes up in for searches in reference to that function. I can make curl request just fine but this multi stuff is killing me. Any help?

  • 写回答

1条回答 默认 最新

  • dqjmq28248 2017-06-26 21:05
    关注

    It was a self made function from the tutorial you are following.. Every comment explains what it does in the tutorial you are on.. ^_^

    // 15. adds a url to the multi handle

    function add_url_to_multi_handle($mh, $url_list) {
        static $index = 0;
    
        // if we have another url to get
        if ($url_list[$index]) {
    
            // new curl handle
            $ch = curl_init();
    
            // set the url
            curl_setopt($ch, CURLOPT_URL, $url_list[$index]);
            // to prevent the response from being outputted
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            // follow redirections
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            // do not need the body. this saves bandwidth and time
            curl_setopt($ch, CURLOPT_NOBODY, 1);
    
            // add it to the multi handle
            curl_multi_add_handle($mh, $ch);
    
    
            // increment so next url is used next time
            $index++;
    
            return true;
        } else {
    
            // we are done adding new URLs
            return false;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line