PHP 8.3.4 Released!

curl_close

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

curl_closecURL セッションを閉じる

説明

curl_close(CurlHandle $handle): void

注意:

この関数を実行しても何も起こりません。PHP 8.0.0 より前のバージョンでは、この関数はリソースを閉じるのに使われていました。

cURL セッションを閉じ、全てのリソースを開放します。 cURL ハンドル handle も削除されます。

パラメータ

handle

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

戻り値

値を返しません。

変更履歴

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

例1 新しい cURL セッションの初期化とウェブページの取得

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

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

// URL を取得し、それをブラウザに渡します
curl_exec($ch);

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

参考

add a note

User Contributed Notes 1 note

up
2
JS
6 months ago
Although the Note for this call says "Prior to PHP 8.0.0, this function was used to close the resource", I found that PHP 7.4.33 on CentOS is not closing the connection on curl_close.

The workaround if you want to make sure the connection closes immediately after the request is to set the curl option to forbid reuse:

curl_setopt($curl, CURLOPT_FORBID_REUSE, TRUE);
To Top