uTools-Manuals/docs/php/curl_share_setopt.html
2019-04-08 23:22:26 +08:00

167 lines
8.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>为 cURL 共享句柄设置选项。</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.curl-share-setopt" class="refentry">
<div class="refnamediv">
<h1 class="refname">curl_share_setopt</h1>
<p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7)</p><p class="refpurpose"><span class="refname">curl_share_setopt</span> &mdash; <span class="dc-title">为 cURL 共享句柄设置选项。</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.curl-share-setopt-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>curl_share_setopt</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$sh</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span>
) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
为给定的 cURL 共享句柄设置一个选项。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.curl-share-setopt-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">sh</code></dt>
<dd>
<p class="para">
一个由<span class="function"><a href="curl_share_init.html" class="function">curl_share_init()</a></span>函数返回的 cURL 共享句柄。
</p>
</dd>
<dt>
<code class="parameter">option</code></dt>
<dd>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td style="vertical-align: top;"><strong><code>CURLSHOPT_SHARE</code></strong></td>
<td style="vertical-align: top;">
指定要共享的数据类型。
</td>
</tr>
<tr>
<td style="vertical-align: top;"><strong><code>CURLSHOPT_UNSHARE</code></strong></td>
<td style="vertical-align: top;">
指定不再共享的数据类型。
</td>
</tr>
</tbody>
</table>
</p>
</dd>
<dt>
<code class="parameter">value</code></dt>
<dd>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td style="vertical-align: top;"><strong><code>CURL_LOCK_DATA_COOKIE</code></strong></td>
<td style="vertical-align: top;">
共享 cookie 数据。
</td>
</tr>
<tr>
<td style="vertical-align: top;"><strong><code>CURL_LOCK_DATA_DNS</code></strong></td>
<td style="vertical-align: top;">
共享 DNS 缓存。注意,当你使用 cURL 多句柄时,默认所有添加在同一个多句柄的句柄都将会共享 DNS 缓存。
</td>
</tr>
<tr>
<td style="vertical-align: top;"><strong><code>CURL_LOCK_DATA_SSL_SESSION</code></strong></td>
<td style="vertical-align: top;">
共享 SSL 的 session ID, 在重连同样的服务器时减少 SSL 握手时间。注意SSL 的 session ID 在同一个的句柄中默认是重复使用的。
</td>
</tr>
</tbody>
</table>
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.curl-share-setopt-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.curl-share-setopt-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5256">
<p><strong>Example #1 <span class="function"><strong>curl_share_setopt()</strong></span> 函数的范例:</strong></p>
<div class="example-contents"><p>
以下范例将会创建一个 cURL 共享句柄,并且往其中添加两个 cURL 句柄,最后共享这两个 cURL 句柄的 cookie 数据运行。
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;cURL&nbsp;share&nbsp;handle&nbsp;and&nbsp;set&nbsp;it&nbsp;to&nbsp;share&nbsp;cookie&nbsp;data<br /></span><span style="color: #0000BB">$sh&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_share_init</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">curl_share_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$sh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLSHOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURL_LOCK_DATA_COOKIE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;first&nbsp;cURL&nbsp;handle&nbsp;and&nbsp;assign&nbsp;the&nbsp;share&nbsp;handle&nbsp;to&nbsp;it<br /></span><span style="color: #0000BB">$ch1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute&nbsp;the&nbsp;first&nbsp;cURL&nbsp;handle<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;second&nbsp;cURL&nbsp;handle&nbsp;and&nbsp;assign&nbsp;the&nbsp;share&nbsp;handle&nbsp;to&nbsp;it<br /></span><span style="color: #0000BB">$ch2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://php.net/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute&nbsp;the&nbsp;second&nbsp;cURL&nbsp;handle<br />//&nbsp;&nbsp;all&nbsp;cookies&nbsp;from&nbsp;$ch1&nbsp;handle&nbsp;are&nbsp;shared&nbsp;with&nbsp;$ch2&nbsp;handle<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Close&nbsp;the&nbsp;cURL&nbsp;share&nbsp;handle<br /></span><span style="color: #0000BB">curl_share_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Close&nbsp;the&nbsp;cURL&nbsp;handles<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
</div></div></div></body></html>