mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
167 lines
8.5 KiB
HTML
167 lines
8.5 KiB
HTML
<!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 >= 5.5.0, PHP 7)</p><p class="refpurpose"><span class="refname">curl_share_setopt</span> — <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"><?php<br /></span><span style="color: #FF8000">// Create cURL share handle and set it to share cookie data<br /></span><span style="color: #0000BB">$sh </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">CURLSHOPT_SHARE</span><span style="color: #007700">, </span><span style="color: #0000BB">CURL_LOCK_DATA_COOKIE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Initialize the first cURL handle and assign the share handle to it<br /></span><span style="color: #0000BB">$ch1 </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">, </span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Execute the first cURL 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">// Initialize the second cURL handle and assign the share handle to it<br /></span><span style="color: #0000BB">$ch2 </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">, </span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Execute the second cURL handle<br />// all cookies from $ch1 handle are shared with $ch2 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">// Close the cURL share 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">// Close the cURL 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">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |