LoginSignup
tetsunari
@tetsunari

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

php curl_closeを明示的に呼ばない場合の挙動について

Q&A

解決したいこと

phpではcurl_initでcURL セッションを初期化しcurl_close でcURL セッションを終了しているのですが、curl_closeを明示的に呼ばない場合の挙動はどうなっているのでしょうか?

例)
cURL関数を用いてAPIを叩いていいるのですが、curl_closeをする前にcurl_getinfoでhttp_codeが200以外の時に処理を止めています。
200番台以外の時はcurl_closeが呼ばれていないのですが、処理は通常に動作します。。

curl_closeを明示的に呼ばない場合の挙動はどうなっているのでしょうか?

$curl = curl_init();
// ...[略]...
$curl_info = curl_getinfo($curl);
if ($curl_info['http_code'] !== 200) return;
// ...[略]...
curl_close($curl);
0

1Answer

This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource.

とあるのでPHP8以降であれば呼んでも呼ばなくても変わらなさそうです。

0

Comments

  1. @tetsunari

    Questioner
    回答ありがとうございます!
    php8ではそうなのですね。自分がphp8を使っていませんでして。。。

Your answer might help someone💌