php curl returns an error method: first create a cURL handle pointing to a non-existent location; then use the "curl_error" function to return an error message with a clear text of the latest cURL operation; finally close the handle. .
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How does php curl return an error?
curl_error — Returns a string that protects the most recent error in the current session
Description
string curl_error ( resource $ch )
Returns an explicit textual error message for the most recent cURL operation.
Parameters
ch
The cURL handle returned by curl_init().
Return Value
Returns an error message or '' (empty string) if no error occurs.
Example
<?php // 创建一个指向一个不存在的位置的cURL句柄 $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 '操作完成没有任何错误'; } // 关闭句柄 curl_close($ch); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How does php curl return an error?. For more information, please follow other related articles on the PHP Chinese website!