标题:
[提问]
OPENSSL问题,使用fsockopen()函数提示错误
[打印本页]
作者:
artrogue
时间:
2017-5-13 07:57
标题:
OPENSSL问题,使用fsockopen()函数提示错误
本帖最后由 artrogue 于 2017-5-13 08:23 编辑
环境配置
系统环境 CentOS
7.2
WDCP v3.2.2 lanmp
PHP 多版本 指定使用5.6
OpenSSL 1.0.2h 3 May 2016
php.ini相关设置
allow_url_fopen = On
allow_url_include = On
openssl.cafile= /www/wdlinux/nginx/conf/cert/cacert.pem (后来下载OPENSSL证书放上的)
问题描述
PHP程序中使用
$matches = parse_url($url);
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$transports = '';
if($matches['scheme'] == 'https') { //判断是否使用HTTPS
$transports = 'ssl://'; //如使用HTTPS则使用SSL协议
$port = !empty($matches['port']) ? $matches['port'] : 443; //如使用HTTPS端口使用443
} else {
$transports = 'tcp://'; //如没有使用HTTPS则使用tcp协议
$port = !empty($matches['port']) ? $matches['port'] : 80;//如没有使用HTTPS则使用80端口
}
$fp = @fsockopen(($transports . $host), $port, $errno, $errstr, $timeout);
复制代码
其中此PHP文件运行无效果,生成error_log信息如下
<?php exit;?>05-12 20:40:12 | 2 | fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed | ../client.class.php | 395
<?php exit;?>05-12 20:40:12 | 2 | fsockopen(): Failed to enable crypto | ../client.class.php | 395
<?php exit;?>05-12 20:40:12 | 2 | fsockopen(): unable to connect to ssl://www.xxx.net:443 (Unknown error) | p../client.class.php | 395
复制代码
395行就是以上代码中的
$fp = @fsockopen(($transports . $host), $port, $errno, $errstr, $timeout);
百度很多资料,没找到相关PHP报错的资料,找到一些E文网站,大约是说没有下载openssl根证书,于是更具资料提示下载OpenSSL根证书,并在php.ini设置OPENSSL证书位置,还是不能正常运行,报以上错误,估计是OPENSSL环境配置的问题,请admin指点
作者:
artrogue
时间:
2017-5-13 08:58
我百度了一些错误关键词
OpenSSL Error messages:error:14090086
SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
好像都是说关于openssl根证书的问题,大神能帮看下如何解决吗
作者:
artrogue
时间:
2017-5-14 12:35
本帖最后由 artrogue 于 2017-5-14 12:36 编辑
经过三天的摸索和查找资料,现在我已确定问题所在
此问题和wdcp无关,和php版本以及openssl相关
主要是因为php在5.6版本(包含5.6)以后的所有版本中如使用fsockopen() 或file_get_content()函数获取https站点的信息,OPENSSL会验证对方站点的SSL证书颁发机构是否可信,如果没有下载openssl根证书并在php.ini中设置openssl根证书路径,就会造成无法验证对方网站SSL证书是否可信,就无法使用上述两个函数获取到内容同时生成PHP警告信息,php5.6以前的老版本中此验证功能是没有开启或者说是没有作用的。所以php5.6以前的版本不存在此问题!
OpenSSL Error messages:error:14090086
SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
特在此说明原因,同时希望我这两天的折腾对以后遇到同样问题的朋友有所帮助少走弯路
欢迎光临 WDlinux官方论坛 (http://wdlinux.cn/bbs/)
Powered by Discuz! 7.2