file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

前端 未结 16 2023
情歌与酒
情歌与酒 2020-11-22 04:31

I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks li

16条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 04:49

    Reason for this error is that PHP does not have a list of trusted certificate authorities.

    PHP 5.6 and later try to load the CAs trusted by the system automatically. Issues with that can be fixed. See http://php.net/manual/en/migration56.openssl.php for more information.

    PHP 5.5 and earlier are really hard to setup correctly since you manually have to specify the CA bundle in each request context, a thing you do not want to sprinkle around your code. So I decided for my code that for PHP versions < 5.6, SSL verification simply gets disabled:

    $req = new HTTP_Request2($url);
    if (version_compare(PHP_VERSION, '5.6.0', '<')) {
        //correct ssl validation on php 5.5 is a pain, so disable
        $req->setConfig('ssl_verify_host', false);
        $req->setConfig('ssl_verify_peer', false);
    }
    

提交回复
热议问题