curl_errno
(PHP 4 >= 4.0.3, PHP 5)
curl_errno — Возвращает код последней ошибки
Описание
int curl_errno
( resource
$ch
)Возвращает код ошибки последней операции cURL.
Возвращаемые значения
Возвращает номер ошибки или 0 (ноль), если ошибки не произошло.
Примеры
Пример #1 Пример использования curl_errno()
<?php
// Создаем дескриптор curl к несуществующему адресу
$ch = curl_init('http://404.php.net/');
// Запускаем
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
// Проверяем наличие ошибки
if(curl_errno($ch))
{
echo 'Ошибка curl: ' . curl_error($ch);
}
// Закрываем дескриптор
curl_close($ch);
?>
Смотрите также
- curl_error() - Возвращает строку с описанием последней ошибки текущего сеанса
- » Коды ошибок cURL
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие службы
- Клиентская библиотека работы с URL
- curl_close
- curl_copy_handle
- curl_errno
- curl_error
- curl_escape
- curl_exec
- curl_file_create
- curl_getinfo
- curl_init
- curl_multi_add_handle
- curl_multi_close
- curl_multi_exec
- curl_multi_getcontent
- curl_multi_info_read
- curl_multi_init
- curl_multi_remove_handle
- curl_multi_select
- curl_multi_setopt
- curl_multi_strerror
- curl_pause
- curl_reset
- curl_setopt_array
- curl_setopt
- curl_share_close
- curl_share_init
- curl_share_setopt
- curl_strerror
- curl_unescape
- curl_version
Коментарии
Note that you can detect errors using curl_multi_info_read() in the curl_multi_exec() loop that don't show up later using curl_errno(). This seems particularly true of connection errors.
if someone need more information about curl errors
<?php
$error_codes=array(
[1] => 'CURLE_UNSUPPORTED_PROTOCOL',
[2] => 'CURLE_FAILED_INIT',
[3] => 'CURLE_URL_MALFORMAT',
[4] => 'CURLE_URL_MALFORMAT_USER',
[5] => 'CURLE_COULDNT_RESOLVE_PROXY',
[6] => 'CURLE_COULDNT_RESOLVE_HOST',
[7] => 'CURLE_COULDNT_CONNECT',
[8] => 'CURLE_FTP_WEIRD_SERVER_REPLY',
[9] => 'CURLE_REMOTE_ACCESS_DENIED',
[11] => 'CURLE_FTP_WEIRD_PASS_REPLY',
[13] => 'CURLE_FTP_WEIRD_PASV_REPLY',
[14]=>'CURLE_FTP_WEIRD_227_FORMAT',
[15] => 'CURLE_FTP_CANT_GET_HOST',
[17] => 'CURLE_FTP_COULDNT_SET_TYPE',
[18] => 'CURLE_PARTIAL_FILE',
[19] => 'CURLE_FTP_COULDNT_RETR_FILE',
[21] => 'CURLE_QUOTE_ERROR',
[22] => 'CURLE_HTTP_RETURNED_ERROR',
[23] => 'CURLE_WRITE_ERROR',
[25] => 'CURLE_UPLOAD_FAILED',
[26] => 'CURLE_READ_ERROR',
[27] => 'CURLE_OUT_OF_MEMORY',
[28] => 'CURLE_OPERATION_TIMEDOUT',
[30] => 'CURLE_FTP_PORT_FAILED',
[31] => 'CURLE_FTP_COULDNT_USE_REST',
[33] => 'CURLE_RANGE_ERROR',
[34] => 'CURLE_HTTP_POST_ERROR',
[35] => 'CURLE_SSL_CONNECT_ERROR',
[36] => 'CURLE_BAD_DOWNLOAD_RESUME',
[37] => 'CURLE_FILE_COULDNT_READ_FILE',
[38] => 'CURLE_LDAP_CANNOT_BIND',
[39] => 'CURLE_LDAP_SEARCH_FAILED',
[41] => 'CURLE_FUNCTION_NOT_FOUND',
[42] => 'CURLE_ABORTED_BY_CALLBACK',
[43] => 'CURLE_BAD_FUNCTION_ARGUMENT',
[45] => 'CURLE_INTERFACE_FAILED',
[47] => 'CURLE_TOO_MANY_REDIRECTS',
[48] => 'CURLE_UNKNOWN_TELNET_OPTION',
[49] => 'CURLE_TELNET_OPTION_SYNTAX',
[51] => 'CURLE_PEER_FAILED_VERIFICATION',
[52] => 'CURLE_GOT_NOTHING',
[53] => 'CURLE_SSL_ENGINE_NOTFOUND',
[54] => 'CURLE_SSL_ENGINE_SETFAILED',
[55] => 'CURLE_SEND_ERROR',
[56] => 'CURLE_RECV_ERROR',
[58] => 'CURLE_SSL_CERTPROBLEM',
[59] => 'CURLE_SSL_CIPHER',
[60] => 'CURLE_SSL_CACERT',
[61] => 'CURLE_BAD_CONTENT_ENCODING',
[62] => 'CURLE_LDAP_INVALID_URL',
[63] => 'CURLE_FILESIZE_EXCEEDED',
[64] => 'CURLE_USE_SSL_FAILED',
[65] => 'CURLE_SEND_FAIL_REWIND',
[66] => 'CURLE_SSL_ENGINE_INITFAILED',
[67] => 'CURLE_LOGIN_DENIED',
[68] => 'CURLE_TFTP_NOTFOUND',
[69] => 'CURLE_TFTP_PERM',
[70] => 'CURLE_REMOTE_DISK_FULL',
[71] => 'CURLE_TFTP_ILLEGAL',
[72] => 'CURLE_TFTP_UNKNOWNID',
[73] => 'CURLE_REMOTE_FILE_EXISTS',
[74] => 'CURLE_TFTP_NOSUCHUSER',
[75] => 'CURLE_CONV_FAILED',
[76] => 'CURLE_CONV_REQD',
[77] => 'CURLE_SSL_CACERT_BADFILE',
[78] => 'CURLE_REMOTE_FILE_NOT_FOUND',
[79] => 'CURLE_SSH',
[80] => 'CURLE_SSL_SHUTDOWN_FAILED',
[81] => 'CURLE_AGAIN',
[82] => 'CURLE_SSL_CRL_BADFILE',
[83] => 'CURLE_SSL_ISSUER_ERROR',
[84] => 'CURLE_FTP_PRET_FAILED',
[84] => 'CURLE_FTP_PRET_FAILED',
[85] => 'CURLE_RTSP_CSEQ_ERROR',
[86] => 'CURLE_RTSP_SESSION_ERROR',
[87] => 'CURLE_FTP_BAD_FILE_LIST',
[88] => 'CURLE_CHUNK_FAILED');
?>
you should look on curl.constants for the error codes, not on the linked official curl doc. some of the error codes are different, at least the one mentioned on the other page:
in PHP the curl error number 28 is called
CURLE_OPERATION_TIMEOUTED
while in the official site is:
CURLE_OPERATION_TIMEDOUT
All available curl error constants and values in PHP 5.4.7 on FreeBSD 8.2-RELEASE:
CURLE_UNSUPPORTED_PROTOCOL => 1
CURLE_FAILED_INIT => 2
CURLE_URL_MALFORMAT => 3
CURLE_URL_MALFORMAT_USER => 4
CURLE_COULDNT_RESOLVE_PROXY => 5
CURLE_COULDNT_RESOLVE_HOST => 6
CURLE_COULDNT_CONNECT => 7
CURLE_FTP_WEIRD_SERVER_REPLY => 8
CURLE_FTP_ACCESS_DENIED => 9
CURLE_FTP_USER_PASSWORD_INCORRECT => 10
CURLE_FTP_WEIRD_PASS_REPLY => 11
CURLE_FTP_WEIRD_USER_REPLY => 12
CURLE_FTP_WEIRD_PASV_REPLY => 13
CURLE_FTP_WEIRD_227_FORMAT => 14
CURLE_FTP_CANT_GET_HOST => 15
CURLE_FTP_CANT_RECONNECT => 16
CURLE_FTP_COULDNT_SET_BINARY => 17
CURLE_PARTIAL_FILE => 18
CURLE_FTP_COULDNT_RETR_FILE => 19
CURLE_FTP_WRITE_ERROR => 20
CURLE_FTP_QUOTE_ERROR => 21
CURLE_HTTP_NOT_FOUND => 22
CURLE_WRITE_ERROR => 23
CURLE_MALFORMAT_USER => 24
CURLE_FTP_COULDNT_STOR_FILE => 25
CURLE_READ_ERROR => 26
CURLE_OUT_OF_MEMORY => 27
CURLE_OPERATION_TIMEOUTED => 28
CURLE_FTP_COULDNT_SET_ASCII => 29
CURLE_FTP_PORT_FAILED => 30
CURLE_FTP_COULDNT_USE_REST => 31
CURLE_FTP_COULDNT_GET_SIZE => 32
CURLE_HTTP_RANGE_ERROR => 33
CURLE_HTTP_POST_ERROR => 34
CURLE_SSL_CONNECT_ERROR => 35
CURLE_FTP_BAD_DOWNLOAD_RESUME => 36
CURLE_FILE_COULDNT_READ_FILE => 37
CURLE_LDAP_CANNOT_BIND => 38
CURLE_LDAP_SEARCH_FAILED => 39
CURLE_LIBRARY_NOT_FOUND => 40
CURLE_FUNCTION_NOT_FOUND => 41
CURLE_ABORTED_BY_CALLBACK => 42
CURLE_BAD_FUNCTION_ARGUMENT => 43
CURLE_BAD_CALLING_ORDER => 44
CURLE_HTTP_PORT_FAILED => 45
CURLE_BAD_PASSWORD_ENTERED => 46
CURLE_TOO_MANY_REDIRECTS => 47
CURLE_UNKNOWN_TELNET_OPTION => 48
CURLE_TELNET_OPTION_SYNTAX => 49
CURLE_OBSOLETE => 50
CURLE_SSL_PEER_CERTIFICATE => 51
CURLE_GOT_NOTHING => 52
CURLE_SSL_ENGINE_NOTFOUND => 53
CURLE_SSL_ENGINE_SETFAILED => 54
CURLE_SEND_ERROR => 55
CURLE_RECV_ERROR => 56
CURLE_SHARE_IN_USE => 57
CURLE_SSL_CERTPROBLEM => 58
CURLE_SSL_CIPHER => 59
CURLE_SSL_CACERT => 60
CURLE_BAD_CONTENT_ENCODING => 61
CURLE_LDAP_INVALID_URL => 62
CURLE_FILESIZE_EXCEEDED => 63
CURLE_FTP_SSL_FAILED] => 64
To coder.ua[at]gmail.com:
Please note some errors have more than one constants:
[CURLE_FTP_PARTIAL_FILE] 18
[CURLE_PARTIAL_FILE] 18
[CURLE_HTTP_NOT_FOUND] 22
[CURLE_HTTP_RETURNED_ERROR] 22
[CURLE_OPERATION_TIMEDOUT] 28
[CURLE_OPERATION_TIMEOUTED] 28
[CURLE_BAD_DOWNLOAD_RESUME] 36
[CURLE_FTP_BAD_DOWNLOAD_RESUME] 36
Gets a current list of all CURLE_* error constants, their applicable error messages, and their applicable error codes. Useful for making wrapper classes or for mapping cURL errors to specific Exception objects.
<?php
$list = get_defined_constants(TRUE);
$list = preg_grep('/^CURLE_/', array_flip($list['curl']));
$result = array();
foreach ($list as $const) {
$result[$const] = array
(
'code' => constant($const),
'message' => curl_strerror(constant($const))
);
}
echo "<pre>";
echo print_r($result, TRUE);
echo "</pre>";
/!\ ATTENTION if you are using curl multi handles
This function returns 0 in error conditions when run on curl handles accessed via curl_multi_info_read().
You must look at the data returned by curl_multi_info_read() for the true errno. The data is over there instead.
The manual above only mentions how to get an error description from the cURL handle ($ch) using curl_error():
<?php
$description = curl_error($ch);
?>
But you can also get a description from the error number itself using curl_strerror():
<?php
$description = curl_strerror(curl_errno($ch));
?>
The latter can be useful if you only have access to the error number but not to the cURL handle.
CURLcode v7.81 reversed array for PHP (from \curl\include\curl\curl.h l.495)
https://gist.github.com/nono303/de1256f55e26fdbcc3e0d72e397ac4a1