略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: curl_share_init

2024-03-29

curl_share_init

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

curl_share_init初始化一个 cURL 共享句柄。

说明

curl_share_init(): resource

运行在 cURL 句柄之间共享数据。

参数

此函数没有参数。

返回值

返回类型为"cURL 共享句柄"的资源。

范例

示例 #1 curl_share_init() 函数的范例:

以下范例将会创建一个 cURL 共享句柄,并且往其中添加两个 cURL 句柄,最后用共享的 cookie 数据运行它们。

<?php
// 创建 cURL 共享句柄,并设置共享 cookie 数据
$sh curl_share_init();
curl_share_setopt($shCURLSHOPT_SHARECURL_LOCK_DATA_COOKIE);

// 初始化第一个 cURL 句柄,并将它设置到共享句柄
$ch1 curl_init("http://example.com/");
curl_setopt($ch1CURLOPT_SHARE$sh);

// 执行第一个 cURL 句柄
curl_exec($ch1);

// 初始化第二个 cURL 句柄,并将它设置到共享句柄
$ch2 curl_init("http://php.net/");
curl_setopt($ch2CURLOPT_SHARE$sh);

// 执行第二个 cURL 句柄
//  all cookies from $ch1 handle are shared with $ch2 handle
curl_exec($ch2);

// 关闭 cURL 共享句柄
curl_share_close($sh);

// 关闭 cURL 共享句柄
curl_close($ch1);
curl_close($ch2);
?>

参见

add a noteadd a note

User Contributed Notes 1 note

up
1
Robert Chapin
4 years ago
Cookie handling is DISABLED by default.  The following must be used prior to CURLOPT_SHARE.

curl_setopt($ch1, CURLOPT_COOKIEFILE, "");
curl_setopt($ch2, CURLOPT_COOKIEFILE, "");

Also, do not attempt to use CURLOPT_SHARE with curl_setopt_array because this can cause the options to be set in the wrong order, which will fail.

官方地址:https://www.php.net/manual/en/function.curl-share-init.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3