curl_multi_strerror()

1. 定义

该函数与curl_strerror()类似,都是通过给定的错误码,输出其对应的字符串信息。 如果错误码不属于CURLM 错误代码常量,将返回NULL。

2. 语法

curl_multi_strerror ( int $errornum ) : string

3. 参数说明

参数 可选性 数据类型 描述
$errornum 必需 整型 属于CURLM 错误代码的常量值

4. 示例

<?php

// curl_multi_strerror()
// 通过给定的错误码,输出其对应的字符串信息

// 由于该函数并不直接涉及 curl 传输会话,所以可以输出所有的 curl 传输会话的错误信息

for ($errcode = -1; $errcode < 100; $errcode++) {
    $info[$errcode] = curl_multi_strerror($errcode);
}
// 去除不符合要求的(值为 Unknown error )的,这里使用 array_filter() 函数
$info = array_filter($info, 'filter', ARRAY_FILTER_USE_BOTH);
print_r($info);

function filter($value, $key)
{
    if ($value != 'Unknown error') return true;
}

/* 输出:
Array
(
    [-1] => Please call curl_multi_perform() soon
    [0] => No error
    [1] => Invalid multi handle
    [2] => Invalid easy handle
    [3] => Out of memory
    [4] => Internal error
    [5] => Invalid socket argument
    [6] => Unknown option
    [7] => The easy handle is already added to a multi handle
    [8] => API function called from within callback
)
 */

5. 延展阅读