1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="function.curl-share-init-persistent" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>curl_share_init_persistent</refname>
<refpurpose>Initialize a <emphasis role="bold">persistent</emphasis> cURL share handle</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>CurlSharePersistentHandle</type><methodname>curl_share_init_persistent</methodname>
<methodparam><type>array</type><parameter>share_options</parameter></methodparam>
</methodsynopsis>
<simpara>
Initialize a <emphasis role="bold">persistent</emphasis> cURL share handle
with the given share options. Unlike <function>curl_share_init</function>,
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
<parameter>share_options</parameter> is found, it will be reused.
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>share_options</parameter></term>
<listitem>
<simpara>
A non-empty array of <constant>CURL_LOCK_DATA_<replaceable>*</replaceable></constant> constants.
</simpara>
<note>
<simpara>
<constant>CURL_LOCK_DATA_COOKIE</constant>
is not allowed and, if specified, this function will throw a
<exceptionname>ValueError</exceptionname>. Sharing cookies between PHP
requests may lead to inadvertently mixing up sensitive cookies between users.
</simpara>
</note>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
Returns a <classname>CurlSharePersistentHandle</classname>.
</simpara>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<itemizedlist>
<listitem>
<simpara>
If <parameter>share_options</parameter> is empty, this function throws
a <exceptionname>ValueError</exceptionname>.
</simpara>
</listitem>
<listitem>
<simpara>
If <parameter>share_options</parameter> contains a value not matching
a <constant>CURL_LOCK_DATA_<replaceable>*</replaceable></constant>,
this function throws a <classname>ValueError</classname>.
</simpara>
</listitem>
<listitem>
<simpara>
If <parameter>share_options</parameter> contains
<constant>CURL_LOCK_DATA_COOKIE</constant>, this function throws a
<exceptionname>ValueError</exceptionname>.
</simpara>
</listitem>
<listitem>
<simpara>
If <parameter>share_options</parameter> contains a non-integer value,
this function throws a <exceptionname>TypeError</exceptionname>.
</simpara>
</listitem>
</itemizedlist>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="function.curl-share-init-persistent.example.basic">
<title><function>curl_share_init_persistent</function> example</title>
<simpara>
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, <literal>$sh</literal> will survive between SAPI requests.
</simpara>
<programlisting role="php">
<![CDATA[
<?php
// Create or retrieve a persistent cURL share handle set to share DNS lookups and connections
$sh = curl_share_init_persistent([CURL_LOCK_DATA_DNS, CURL_LOCK_DATA_CONNECT]);
// Initialize the first cURL handle and assign the share handle to it
$ch1 = curl_init("http://example.com/");
curl_setopt($ch1, CURLOPT_SHARE, $sh);
// Execute the first cURL handle. This may reuse the connection from an earlier SAPI request
curl_exec($ch1);
// Initialize the second cURL handle and assign the share handle to it
$ch2 = curl_init("http://example.com/");
curl_setopt($ch2, CURLOPT_SHARE, $sh);
// Execute the second cURL handle. This will reuse the connection from $ch1
curl_exec($ch2);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>curl_setopt</function></member>
<member><function>curl_share_init</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|