“curl_close() is deprecated since 8.5” in WordPress: what to do instead
Short answer
It’s a deprecation notice from PHP 8.5: a plugin or theme calls curl_close() after a web request. Since PHP 8.0 that function does nothing, because PHP frees the connection on its own; PHP 8.5 now says so. The code keeps working. There is no replacement to add: the fix is to stop calling it, or to call it only on PHP older than 8.0. Update the plugin, or send the message to its developer.
The message, exactly
Many plugins fetch data from other sites with cURL and close the connection afterwards. On PHP 8.4 that runs silently; PHP 8.5 adds a notice that explains itself:
example.php
<?php
$handle = curl_init();
curl_close($handle);
echo "Done\n";
DoneDeprecated: Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0 in /var/www/html/example.php on line 3
Donephp.net, in the PHP 8.5 deprecations: “The curl_close() function has been deprecated, as CurlHandle objects are freed automatically.” (php.net) And on the function’s own page: “This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource.” (php.net)
Why it does nothing
Before PHP 8.0, a cURL connection was a resource that stayed open until the code closed it. PHP 8.0 turned it into an object that PHP frees on its own when nothing uses it any more. Since then curl_close() has been an empty call; PHP 8.5 only makes that visible.
Is it urgent?
No. The result is the same on 8.4 and 8.5. A future PHP version is expected to remove the function, and a plugin that makes many requests writes the notice each time, so it should be fixed.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates).
- Already on the latest version? Send the full message to its developer: the fix is a one-line removal.
- Keep notices off your pages: the WordPress debug log shows how.
A check that reads code finds every call while your site still runs PHP 8.4; CompatNav reports it as a deprecation notice with the file and line. The other PHP 8.5 changes: WordPress and PHP 8.5.
Key takeaways
- It’s a deprecation notice from PHP 8.5; the code keeps working.
curl_close()has had no effect since PHP 8.0: PHP frees cURL handles automatically.- The “alternative” is nothing: remove the call, or keep it only for PHP older than 8.0.
curl_share_close()got the same treatment in PHP 8.5.- A check that reads code finds every call before you upgrade.
Frequently asked questions
What is the alternative to curl_close()?
None is needed. Since PHP 8.0 the cURL handle is freed automatically when the code no longer uses it. Removing the call changes nothing on PHP 8.0 and later.
Should I unset the handle instead?
Not necessary in most code. A handle is freed when nothing refers to it any more, for example at the end of the function that created it.
Is it urgent?
No. It’s a notice; the code works as before. It should still be fixed, because a future PHP version is expected to remove the function.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.