php/doc-en

can we make curl_close() write CURLOPT_COOKIEJAR again?

開放

#2,239 建立於 2023年1月20日

 (10 則留言) (0 個反應) (0 位負責人)XML (882 個分叉)auto 404
Extension: curlStatus: Verifiedbuggood first issue

倉庫指標

星標
 (596 顆星)
PR 合併指標
 (平均合併 99天 23小時) (30 天內合併 90 個 PR)

描述

Description

The following code:

<?php
declare(strict_types=1);
$ch = curl_init();
$cookiefile_handle = tmpfile();
$cookiefile = stream_get_meta_data($cookiefile_handle)['uri'];
curl_setopt_array($ch, array(
    CURLOPT_COOKIEFILE => $cookiefile,
    CURLOPT_COOKIEJAR => $cookiefile,
    CURLOPT_WRITEFUNCTION => function ($ch, $str) {
        // echo $str;
        return strlen($str);
    },
));
curl_setopt($ch, CURLOPT_URL, "https://example.com/");
curl_exec($ch);
var_dump(file_get_contents($cookiefile));
curl_close($ch);
var_dump(file_get_contents($cookiefile));

will, prior to PHP8.0.0 result in:

$ php7.4 test.php
string(0) ""
string(131) "# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.


and in >=8.0.0 result in

$ php8.2 test.php
string(0) ""
string(0) ""

which breaks scripts relying on curl_close() writing to CURLOPT_COOKIEJAR

PHP Version

PHP 8.0.0

Operating System

No response

貢獻者指南