curl_multi_close

(PHP 5, PHP 7, PHP 8)

curl_multi_close关闭一组 cURL 句柄

说明

curl_multi_close(CurlMultiHandle $multi_handle): void

注意:

此函数无效。在 PHP 8.0.0 之前,用于关闭资源。

关闭一组 cURL 句柄。

参数

multi_handle

curl_multi_init() 返回的 cURL 多个句柄。

返回值

没有返回值。

更新日志

版本 说明
8.0.0 multi_handle expects a CurlMultiHandle instance now; previously, a resource was expected.

示例

示例 #1 curl_multi_close() 示例

此示例将创建两个 cURL 句柄,并把它们加到多句柄中,然后对其异步处理。

<?php
// 创建一对 cURL 资源
$ch1 = curl_init();
$ch2 = curl_init();

// 设置 URL 和其它相应的选项
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

// 创建 cURL 多句柄
$mh = curl_multi_init();

// 新增两个句柄
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

// 执行多句柄
do {
$status = curl_multi_exec($mh, $active);
if (
$active) {
curl_multi_select($mh);
}
} while (
$active && $status == CURLM_OK);

// 关闭全部句柄
curl_multi_remove_handle($mh, $ch1);
curl_close($ch1);
curl_multi_remove_handle($mh, $ch2);
curl_close($ch2);
curl_multi_close($mh);

?>

参见

add a note add a note

User Contributed Notes 1 note

up
1
jonhohle at gmail dot com
16 years ago
curl_multi_close seems to close the curl_multi handle, but not each of the individual curl handles. at least in the PHP 5.3 development build I am using, these each need to be closed manually.

I would recommend the final lines of this example be updated to:

<?php
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_close($ch1);
curl_multi_remove_handle($mh, $ch2);
curl_close($ch2);
curl_multi_close($mh);
?>
To Top