curl_share_strerror()

1. 定义

类似于函数curl_strerror(),根据错误码返回对应消息的字符串。 如果指定的错误码无效(不属于cURL error codes常量值),将返回NULL。

2. 语法

curl_share_strerror ( int $errornum ) : string

3. 参数说明

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

4. 示例

<?php

// curl_share_strerror()
// 类似于函数`curl_strerror()`,根据错误码返回对应消息的字符串

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

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

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

/* 输出:
Array
(
    [0] => No error
    [1] => Unknown share option
    [2] => Share currently in use
    [3] => Invalid share handle
    [4] => Out of memory
    [5] => Feature not enabled in this library
)
 */

5. 延展阅读