curl_share_init

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

curl_share_initInicializar un gestor cURL compartido

Descripción

curl_share_init(): resource

Permite la compartición de datos entre gestores cURL.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve un recurso del tipo "cURL Share Handle".

Ejemplos

Ejemplo #1 Ejemplo con curl_share_init()

Este ejemplo creará un gestor compartido cURL, añadirá dos gestores cURL en él, y entonces los ejecuta con compartición de datos con cookie.

<?php
// Crear gestor compartido cURL y configurarlo para compartir datos con cookie
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);

// Inicializar el primer gestor cURL y asignarlo al gestor compartido
$ch1 = curl_init("http://example.com/");
curl_setopt($ch1, CURLOPT_SHARE, $sh);

// Ejecutar el primer gestor cURL
curl_exec($ch1);

// Inicializar el segundo gestor cURL y asignarlo al gestor compartido
$ch2 = curl_init("http://php.net/");
curl_setopt($ch2, CURLOPT_SHARE, $sh);

// Ejecutar el segundo gestor cURL
// todas las cookies del gestor $ch1 son compartidas con el gestor $ch2
curl_exec($ch2);

// Cerrar el gestor compartido cURL
curl_share_close($sh);

// Cerrar los gestores cURL
curl_close($ch1);
curl_close($ch2);
?>

Ver también

add a note add a note

User Contributed Notes 1 note

up
1
Robert Chapin
6 years ago
Cookie handling is DISABLED by default.  The following must be used prior to CURLOPT_SHARE.

curl_setopt($ch1, CURLOPT_COOKIEFILE, "");
curl_setopt($ch2, CURLOPT_COOKIEFILE, "");

Also, do not attempt to use CURLOPT_SHARE with curl_setopt_array because this can cause the options to be set in the wrong order, which will fail.
To Top