Issue
The following script (stripped down for clarity and simplicity) has run fine for years, but since upgrading from php 5 to 8, the cookie file created is no longer deleted by the unlink command, despite it reporting success, leading to a build-up of these cookie files.
If I take out the CURLOPT_COOKIEJAR line, then the file is deleted just fine.
<?php
$my_cookie=tempnam("./","XX");
$ch = curl_init();
curl_setopt ($ch, CURLOPT_COOKIEJAR, $my_cookie);
curl_close($ch);
if (unlink($my_cookie)) {
echo "success - $my_cookie unlinked<BR>";
} else {
echo "fail";
}
?>
Any ideas?
Solution
curl_close($ch);
does nothing in PHP >= 8.0.0, so the cookie file doesn't actually exist (yet) when you're trying to delete it.
Replace curl_close($ch);
with unset($ch);
. This will write the cookie file.
See documentation of curl_close
:
Note: This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource.
Answered By - volkerschulz Answer Checked By - Cary Denson (WPSolving Admin)