在 curl_close() 之后我無法訪問 cookie 檔案,盡管它已成功創建(不是檔案路徑問題)。因此,我在 curl_close() 之后添加了 15 秒的睡眠時間,我注意到 cookie 檔案僅在 15 秒后創建,即在整個 php 檔案結束后。
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$response = curl_exec($ch);
curl_close($ch);
//I can't find the cookie file here
sleep(15);
uj5u.com熱心網友回復:
根據手動輸入curl_close:
此功能無效。在 PHP 8.0.0 之前,此函式用于關閉資源。
這篇文章解釋了這個原因:
從 PHP 8 開始,curl_init 函式回傳一個 \CurlHandle 類的實體
因為處理程式現在是物件,所以資源將在垃圾收集期間被銷毀,除非處理程式通過 unset() 呼叫顯式關閉。
要釋放 cookie 檔案資源,您需要取消設定curl 句柄:
unset($ch);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/489589.html
