首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

curl_multi_exec

(PHP 5, PHP 7)

curl_multi_exec - 运行当前cURL句柄的子连接

描述

代码语言:javascript
复制
int curl_multi_exec ( resource $mh , int &$still_running )

处理堆栈中的每个句柄。可以调用此方法,以确定句柄是否需要读取或写入数据。

参数

mh

由curl_multi_init()返回的cURL多重句柄。

still_running

引用标志以指示操作是否仍在运行。

返回值

cURL 预定义常量中定义的cURL代码。

注意:这只会返回有关整个多堆栈的错误。即使此函数返回,个别传输仍可能发生问题CURLM_OK

例子

Example #1 curl_multi_exec() example

这个例子将创建两个cURL句柄,将它们添加到一个多句柄,并异步处理它们。

代码语言:javascript
复制
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);

?>

← curl_multi_errno

curl_multi_getcontent →

扫码关注腾讯云开发者

领取腾讯云代金券