fsockopen打开https链接 Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages

 一个php系统很早的了,后来把环境升级换成https与php5.6以后发现通信api不工作,通过排查发现是fsockopen函数的问题:

报错:Warning:  fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate


解决方法法改造一下fsockopen方法:

//不验证证书

$contextOptions = array(

    'ssl' => array(

        'verify_peer' => false,

        'verify_peer_name' => false

    )

);

//如果有签名的证书

/*

$contextOptions = array(

    'ssl' => array(

        'verify_peer' => true, 

        'cafile' => '/path/to/cacert.pem',

        //'CN_match' => 'xcwmoon.net', // 匹配域名

        'ciphers' => 'HIGH:!SSLv2:!SSLv3',

        'disable_compression' => true,

    )

);

*/

$context = stream_context_create($contextOptions);

$fp = stream_socket_client("ssl://{$host}:{$port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);


Tags php

留言(0)

评论