php8.5
Home/ Manual/ curl / functions/ curl_error

curl_error

PHP function Edit on GitHub ✎

(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)

Return a string containing the last error for the current session

Description

curl_error(CurlHandle $handle): string

Returns a clear text error message for the last cURL operation.

Parameters

Return Values

Returns the error message or '' (the empty string) if no error occurred.

Note

When a CurlHandle is executed via curl_multi_exec(), this function always returns '' (the empty string). To retrieve the error string for each individual handle, pass the result key returned by curl_multi_info_read() to curl_strerror().

Changelog

VersionDescription

Examples

curl_error() example

php
<?php
// Create a curl handle to a non-existing location
$ch = curl_init('http://404.php.net/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}
?>

See Also

Source: reference/curl/functions/curl-error.xml · from the official PHP manual (php/doc-en)