<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.curl-share-init-persistent.php',
    1 => 'curl_share_init_persistent',
    2 => 'Initialize a persistent cURL share handle',
  ),
  'up' => 
  array (
    0 => 'ref.curl.php',
    1 => 'cURL Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.curl-share-init.php',
    1 => 'curl_share_init',
  ),
  'next' => 
  array (
    0 => 'function.curl-share-setopt.php',
    1 => 'curl_share_setopt',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/curl/functions/curl-share-init-persistent.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-persistent" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_share_init_persistent</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.5.0)</p><p class="refpurpose"><span class="refname">curl_share_init_persistent</span> &mdash; <span class="dc-title">Initialize a <strong>persistent</strong> cURL share handle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.curl-share-init-persistent-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_share_init_persistent</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$share_options</code></span>): <span class="type"><a href="class.curlsharepersistenthandle.php" class="type CurlSharePersistentHandle">CurlSharePersistentHandle</a></span></div>

  <p class="simpara">
   Initialize a <strong>persistent</strong> cURL share handle
   with the given share options. Unlike <span class="function"><a href="function.curl-share-init.php" class="function">curl_share_init()</a></span>,
   handles created by this function will not be destroyed at the end of the
   PHP request. If a persistent share handle with the same set of
   <code class="parameter">share_options</code> is found, it will be reused.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-share-init-persistent-parameters">
  <h3 class="title">Elenco dei parametri</h3>

  <dl>
   
    <dt><code class="parameter">share_options</code></dt>
    <dd>
     <span class="simpara">
      A non-empty array of <strong><code><a href="curl.constants.php#constant.curl-lock-data-connect">CURL_LOCK_DATA_<span class="replaceable">*</span></a></code></strong> constants.
     </span>
     <blockquote class="note"><p><strong class="note">Nota</strong>: 
      <span class="simpara">
       <strong><code><a href="curl.constants.php#constant.curl-lock-data-cookie">CURL_LOCK_DATA_COOKIE</a></code></strong>
       is not allowed and, if specified, this function will throw a
       <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>. Sharing cookies between PHP
       requests may lead to inadvertently mixing up sensitive cookies between users.
      </span>
     </p></blockquote>
    </dd>
   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-share-init-persistent-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Returns a <span class="classname"><a href="class.curlsharepersistenthandle.php" class="classname">CurlSharePersistentHandle</a></span>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.curl-share-init-persistent-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     If <code class="parameter">share_options</code> is empty, this function throws
     a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     If <code class="parameter">share_options</code> contains a value not matching
     a <strong><code><a href="curl.constants.php#constant.curl-lock-data-connect">CURL_LOCK_DATA_<span class="replaceable">*</span></a></code></strong>,
     this function throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     If <code class="parameter">share_options</code> contains
     <strong><code><a href="curl.constants.php#constant.curl-lock-data-cookie">CURL_LOCK_DATA_COOKIE</a></code></strong>, this function throws a
     <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     If <code class="parameter">share_options</code> contains a non-integer value,
     this function throws a <span class="exceptionname"><a href="class.typeerror.php" class="exceptionname">TypeError</a></span>.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 examples" id="refsect1-function.curl-share-init-persistent-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="function.curl-share-init-persistent.example.basic">
   <p><strong>Example #1 <span class="function"><strong>curl_share_init_persistent()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    This example will create a persistent cURL share handle and demonstrate
    sharing connections between them. If this is executed in a long-lived
    PHP SAPI, <code class="literal">$sh</code> will survive between SAPI requests.
   </p></div>

   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Create or retrieve a persistent cURL share handle set to share DNS lookups and connections<br /></span><span style="color: #0000BB">$sh </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_share_init_persistent</span><span style="color: #007700">([</span><span style="color: #0000BB">CURL_LOCK_DATA_DNS</span><span style="color: #007700">, </span><span style="color: #0000BB">CURL_LOCK_DATA_CONNECT</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. This may reuse the connection from an earlier SAPI request<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://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">$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. This will reuse the connection from $ch1<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: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl-share-init-persistent-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.curl-setopt.php" class="function" rel="rdfs-seeAlso">curl_setopt()</a> - Imposta una opzione per un trasferimento CURL</span></li>
   <li><span class="function"><a href="function.curl-share-init.php" class="function" rel="rdfs-seeAlso">curl_share_init()</a> - Initialize a cURL share handle</span></li>
  </ul>
 </div>


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