如何检查curl是否支持ssl?
如何检查 php curl 是否使用 ssl 编译并支持 ssl? 我的意思是,一个简单的检查curl是否可用的方法是:
if(extension_loaded('curl'))
但如何检查curl是否也支持ssl?我需要进行此检查,因为使用基于 oauth2 的 API 需要 ssl 支持,并且我需要某种方法来快速检查客户端的 php 是否能够在实际使用 oauth2 之前(并且失败)
How can I check if php curl was compiled with ssl and has support for ssl?
I mean, a simple check to see if curl is available would be:
if(extension_loaded('curl'))
but how do I check if curl also has support for ssl? I need this check because ssl support is needed to using oauth2 - based API and I need some way to quickly check if client's php is able to the oauth2 before actually using it (and failing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不确定使用
curl_version()['ssl_version']
是否是个好主意,(例如if (stripos(curl_version()['ssl_version'], "openssl") !== false) {
)正如curl在这里所说 http://curl.haxx.se/docs/faq.html#Does_curl_work_build_with_other
它可能使用 OpenSSL 之外的其他 ssl 库(与分离的 openssl 扩展没有任何关系,curl 有自己的 openssl 库)
如此处所述 http://curl.haxx.se/libcurl/c/curl_version_info.html 似乎使用 CURL_VERSION_SSL 位掩码检查比
curl_version()['ssl_version']
更好。请注意,并非官方 cURL 网站上声明的所有常量都可以在 php 中使用,但只有这四个常量:我通过在 php.ini 中禁用“openssl”扩展在 Windows 上进行了测试,并注意到curl 与分离的 openssl 扩展无关但它有自己的 openssl,换句话说,禁用 openssl 扩展不会影响 $v['ssl_version'];。因此,如果你想检查curl是否支持ssl,你不应该依赖于那个分离的openssl扩展的存在,上面我解释过你也不应该依赖
curl_version()['ssl_version']
。唯一可靠的方法是 CURL_VERSION_SSL 位掩码检查:I am not sure if it is good idea to go with
curl_version()['ssl_version']
, (e.g.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 appears 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: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 $v['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 文件中,您将能够在浏览器中看到 PHP 的所有详细信息:
If you put this code in a PHP file, you will be able to see all of the details for PHP in the browser:
请参阅 http://www.php.net/manual/en/function。 curl-version.php
在 $version['features'] 中,您有一个功能位掩码。通过该位掩码和适当的常量之间的“与”运算,您可以检查某个功能是否已启用。
可能的常量有:
CURL_VERSION_IPV6(整数)
CURL_VERSION_KERBEROS4(整数)
CURL_VERSION_SSL(整数)
CURL_VERSION_LIBZ(整数)
See http://www.php.net/manual/en/function.curl-version.php
In $version['features'] you have a features bitmask. Through an and operation between this bitmask and the proper constant you can check if a feture is enabled.
Possible constants are:
CURL_VERSION_IPV6 (integer)
CURL_VERSION_KERBEROS4 (integer)
CURL_VERSION_SSL (integer)
CURL_VERSION_LIBZ (integer)
AFAIK cURL 没有办法检查 SSL 是否启用或禁用,测试它并捕获会让您确定。
您可以尝试测试一下,看看它是否有效。 (我没有没有 SSL 的服务器可供测试..)
AFAIK cURL doesn't have a way to check if SSL is enabled or disabled, testing it and catching would let you know for sure.
You could try testing this, to see if it works. (I don't have a server without SSL to test on..)
检查
stream_get_wrappers()
的输出,如果 https 在列表中,那么您就可以开始了。Check the output of
stream_get_wrappers()
if https is in the list you're good to go.如果加载了 openssl 扩展,则 cURL 可以使用它。
If the extension openssl is loaded, then cURL can use it.