<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.curl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.curl-share-init.php',
    1 => 'curl_share_init',
    2 => 'Initialize a cURL share handle',
  ),
  'up' => 
  array (
    0 => 'ref.curl.php',
    1 => 'cURL Functions',
  ),
  'prev' => 
  array (
    0 => 'function.curl-share-errno.php',
    1 => 'curl_share_errno',
  ),
  'next' => 
  array (
    0 => 'function.curl-share-init-persistent.php',
    1 => 'curl_share_init_persistent',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/curl/functions/curl-share-init.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.curl-share-init" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_share_init</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">curl_share_init</span> &mdash; <span class="dc-title">Initialize a cURL share handle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.curl-share-init-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_share_init</strong></span>(): <span class="type"><a href="class.curlsharehandle.php" class="type CurlShareHandle">CurlShareHandle</a></span></div>

  <p class="para rdfs-comment">
   Allows to share data between cURL handles.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-share-init-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">This function has no parameters.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-share-init-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a cURL share handle.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.curl-share-init-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       This function returns a <span class="classname"><a href="class.curlsharehandle.php" class="classname">CurlShareHandle</a></span> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was returned.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.curl-share-init-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>curl_share_init()</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">&lt;?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 /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl-share-init-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.curl-share-setopt.php" class="function" rel="rdfs-seeAlso">curl_share_setopt()</a> - Set an option for a cURL share handle</span></li>
    <li><span class="function"><a href="function.curl-share-init-persistent.php" class="function" rel="rdfs-seeAlso">curl_share_init_persistent()</a> - Initialize a persistent cURL share handle</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>