PHP curl_share_setopt函数
PHP 教程
· 2019-01-23 16:57:23
(PHP 5 >= 5.5.0)
curl_share_setopt — 设置 cURL 共享句柄的一个选项。
说明
bool curl_share_setopt ( resource $sh , int $option , string $value )
设置 cURL 共享句柄的一个选项。
参数
sh
通过 curl_share_init() 初始化的共享句柄。
option
| 选项 | 描述 |
|---|---|
CURLSHOPT_SHARE |
指定共享的数据类型 |
CURLSHOPT_UNSHARE |
指定不共享的数据类型 |
value
| 值 | 描述 |
|---|---|
CURL_LOCK_DATA_COOKIE |
共享cookie数据 |
CURL_LOCK_DATA_DNS |
共享 DNS 缓存。 |
CURL_LOCK_DATA_SSL_SESSION |
共享 SSL session ID, 减少连接到相同的服务器花费在SSL 握手时的时间。 |
返回值
成功时返回 TRUE, 或者在失败时返回 FALSE。
实例
该实例将创建一个cURL共享句柄,并添加两个 cURL 句柄,两个句柄共享cookie数据。
<?php
// 创建cURL共享句柄并设置cookie数据
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
// 初始化第一个cURL句柄并指定它为共享句柄
$ch1 = curl_init("http://www.w3cschool.cc/");
curl_setopt($ch1, CURLOPT_SHARE, $sh);
// 执行第一个cURL句柄
curl_exec($ch1);
// 初始化第二个cURL句柄并指定它为共享句柄
$ch2 = curl_init("http://php.net/");
curl_setopt($ch2, CURLOPT_SHARE, $sh);
// 执行第二个cURL句柄
// 所有 $ch1 句柄的数据在 $ch2 句柄中共享
curl_exec($ch2);
// 关闭cURL共享句柄
curl_share_close($sh);
// 关闭cURL句柄
curl_close($ch1);
curl_close($ch2);
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Introduction to Computation and Programming Using Python
John V. Guttag / The MIT Press / 2013-7 / USD 25.00
This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!