<!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>Set an option for a cURL share handle.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-share-init.html">curl_share_init</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-strerror.html">curl_strerror</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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)</p><p class="refpurpose"><span class="refname">curl_share_setopt</span> — <span class="dc-title">Set an option for a cURL share handle.</span></p> </div> <div class="refsect1 description" id="refsect1-function.curl-share-setopt-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <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> )</div> <p class="para rdfs-comment"> Sets an option on the given cURL share handle. </p> </div> <div class="refsect1 parameters" id="refsect1-function.curl-share-setopt-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">sh</code></em></span> <dd> <p class="para"> A cURL share handle returned by <span class="function"><a href="function.curl-share-init.html" class="function">curl_share_init()</a></span>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">option</code></em></span> <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;"> Specifies a type of data that should be shared. </td> </tr> <tr> <td style="vertical-align: top;"><strong><code>CURLSHOPT_UNSHARE</code></strong></td> <td style="vertical-align: top;"> Specifies a type of data that will be no longer shared. </td> </tr> </tbody> </table> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">value</code></em></span> <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;"> Shares cookie data. </td> </tr> <tr> <td style="vertical-align: top;"><strong><code>CURL_LOCK_DATA_DNS</code></strong></td> <td style="vertical-align: top;"> Shares DNS cache. Note that when you use cURL multi handles, all handles added to the same multi handle will share DNS cache by default. </td> </tr> <tr> <td style="vertical-align: top;"><strong><code>CURL_LOCK_DATA_SSL_SESSION</code></strong></td> <td style="vertical-align: top;"> Shares SSL session IDs, reducing the time spent on the SSL handshake when reconnecting to the same server. Note that SSL session IDs are reused withing the same handle by default. </td> </tr> </tbody> </table> </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-function.curl-share-setopt-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.curl-share-setopt-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4229"> <p><strong>Example #1 <span class="function"><strong>curl_share_setopt()</strong></span> example</strong></p> <div class="example-contents"><p> This example will create a cURL share handle, add two cURL handles to it, and then run them with cookie data sharing. </p></div> <div class="example-contents"> <div class="phpcode"><code><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> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-share-init.html">curl_share_init</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-strerror.html">curl_strerror</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>