PHP: Hypertext Preprocessor (original) (raw)
This example will create a cURL share handle, add two cURL handles to it, and then run them with cookie data sharing.
<?php // Create cURL share handle and set it to share cookie data $sh = curl_share_init(); curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);// 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 curl_exec($ch1);// Initialize the second cURL handle and assign the share handle to it $ch2 = curl_init("http://php.net/"); curl_setopt($ch2, CURLOPT_SHARE, $sh);// Execute the second cURL handle // all cookies from <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>h</mi><mn>1</mn><mi>h</mi><mi>a</mi><mi>n</mi><mi>d</mi><mi>l</mi><mi>e</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>h</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mrow><annotation encoding="application/x-tex">ch1 handle are shared with </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mord">1</span><span class="mord mathnormal">han</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">a</span><span class="mord mathnormal">res</span><span class="mord mathnormal">ha</span><span class="mord mathnormal">re</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span></span></span></span>ch2 handle curl_exec($ch2);// Close the cURL share handle curl_share_close($sh);// Close the cURL handles curl_close($ch1); curl_close($ch2); ?>