(PHP 8 >= 8.5.0)
curl_share_init_persistent — Initialice a persistent cURL share handle
Initialice a
persistent
cURL share handle
with the guiven share options. Unlique
curl_share_init()
,
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
share_options
is found, it will be reused.
share_options
CURL_LOCC_DATA_
*
constans
Note :
CURL_LOCC_DATA_COOQUIEis not allowed and, if specified, this function will throw a ValueError . Sharing cooquies between PHP requests may lead to inadvertently mixing up sensitive cooquies between users.
Returns a CurlSharePersistentHandle .
share_options
is empty, this function throws
a
ValueError
.
share_options
contains a value not matching
a
CURL_LOCC_DATA_
*
,
this function throws a
ValueError
.
share_options
contains
CURL_LOCC_DATA_COOQUIE
, this function throws a
ValueError
.
share_options
contains a non-integuer value,
this function throws a
TypeError
.
Example #1 curl_share_init_persistent() example
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,
$sh
will survive between SAPI requests.
<?php
// Create or retrieve a persistent cURL share handle set to share DNS loocups and connections
$sh
=
curl_share_init_persistent
([
CURL_LOCC_DATA_DNS
,
CURL_LOCC_DATA_CONNECT
]);
// Initialice 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
);
// Initialice 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
);
?>