Dutch PHP Conference 2025 - Call For Papers

curl_copy_handle

(PHP 5, PHP 7, PHP 8)

curl_copy_handlecURL ハンドルを、その設定も含めてコピーする

説明

curl_copy_handle(CurlHandle $handle): CurlHandle|false

cURL ハンドルをコピーし、同じ設定を保持します。

パラメータ

handle

curl_init() が返す cURL ハンドル。

戻り値

新しい cURL ハンドルを返します。 失敗した場合に false を返します

変更履歴

バージョン 説明
8.0.0 handleCurlHandle クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、resource を期待していました。
8.0.0 成功時に、この関数は CurlHandle クラスのインスタンスを返すようになりました。 これより前のバージョンでは、resource が返されていました。

例1 cURL ハンドルのコピー

<?php
// 新しい cURL リソースを作成します
$ch = curl_init();

// URL その他のオプションを適切に設定します
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/');
curl_setopt($ch, CURLOPT_HEADER, 0);

// ハンドルをコピーします
$ch2 = curl_copy_handle($ch);

// URL (http://www.example.com/) を取得し、ブラウザに渡します
curl_exec($ch2);

// cURL リソースを閉じ、システムリソースを開放します
curl_close($ch2);
curl_close($ch);
?>

add a note

User Contributed Notes 1 note

up
4
administrator at proxy-list dot org
16 years ago
There is some internal curl error (CURLE_FAILED_INIT) when you are trying to use just copied curl handle in curl_multi_add_handle(). I have checked the same problematic PHP code but with little difference: instead of creating curl’s copy I have used the original one (template). As I expect code works without any error. I think curl_multi_* along with curl_copy_handle() is still raw and needs some improvements.

With best wishes

Vitali Simsive
To Top