PHP Velho Oeste 2024

curl_version

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

curl_version获取 cURL 版本信息

说明

curl_version(): array|false

返回关于 cURL 版本的信息。

参数

此函数没有参数。

返回值

返回关联数组,包含如下元素:

值描述
version_number cURL 24 位版本号
version cURL 版本号,字符串形式
ssl_version_number OpenSSL 24 位版本号
ssl_version OpenSSL 版本号,字符串形式
libz_version zlib 版本号,字符串形式
host 关于编译cURL主机的信息
age  
features 一个CURL_VERSION_XXX常量的位掩码
protocols 数组,包含 cURL 支持的协议名称

更新日志

版本 说明
8.0.0 移除可选的 age 参数。
7.4.0 弃用可选的 age 参数,如果传递值,则忽略。

示例

示例 #1 curl_version() 示例

这个示例将会检查当前 cURL 版本使用 curl_version() 返回的“features”位掩码中哪些特性是可用的。

<?php
// 获取cURL版本数组
$version = curl_version();

// 在cURL编译版本中使用位域来检查某些特性
$bitfields = Array(
'CURL_VERSION_IPV6',
'CURL_VERSION_KERBEROS4',
'CURL_VERSION_SSL',
'CURL_VERSION_LIBZ'
);


foreach(
$bitfields as $feature)
{
echo
$feature . ($version['features'] & constant($feature) ? ' matches' : ' does not match');
echo
PHP_EOL;
}
?>

add a note add a note

User Contributed Notes 1 note

up
-4
nimasdj [AT] yahoo [DOT] com
8 years ago
If you want to check if your curl supports ssl, it is not good idea to go with curl_version()['ssl_version'],
e.g.
<?php
if (stripos(curl_version()['ssl_version'], "openssl") !== false) {
?>
as curl says here http://curl.haxx.se/docs/faq.html#Does_curl_work_build_with_other it may use other ssl library than OpenSSL (which does not have anything to do with that separated openssl extension, curl has its own openssl library) so as described here http://curl.haxx.se/libcurl/c/curl_version_info.html it is better to go with CURL_VERSION_SSL bitmask check rather than curl_version()['ssl_version']. Note that not all of those constants stated on official cURL website are available in php, but only these four constants:

[CURL_VERSION_IPV6] => 1
[CURL_VERSION_KERBEROS4] => 2
[CURL_VERSION_SSL] => 4
[CURL_VERSION_LIBZ] => 8

I tested this on Windows by disabling "openssl" extension in php.ini and noticed curl has nothing to do with that separated openssl extension but it has its own openssl, in other word, disabling openssl extension does not affect on curl_version()['ssl_version']. So if you want to check if curl has support for ssl, you should not rely on existence of that separated openssl extension and above I explained you should not rely on curl_version()['ssl_version'] neither. The only reliable way is CURL_VERSION_SSL bitmask checking:
<?php
if (!curl_version()['features'] & CURL_VERSION_SSL) {
    echo
"SSL is not supported with this cURL installation.";
}
?>
To Top