stream_get_contents():SSL操作失败了代码1。OpenSSL错误消息:错误:0A000126:SSL例程::阅读时意外EOF

发布于 2025-02-05 03:55:35 字数 2593 浏览 3 评论 0原文

我一直在尝试在网站上使用Gmail登录。但是我得到的“ stream_get_contents():SSL操作失败了代码1。OpenSSL错误消息: 错误:0A000126:SSL例程::阅读时意外EOF” 网站建立在YII2上,并在AWS Ubuntu上的NGINX服务器上托管。

php -i | grep -i openssl
SSL Version => OpenSSL/3.0.2
libSSH Version => libssh/0.9.6/openssl/zlib
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 3.0.2 15 Mar 2022
OpenSSL Header Version => OpenSSL 3.0.2 15 Mar 2022
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => /usr/lib/ssl/cert.pem => /usr/lib/ssl/cert.pem
openssl.capath => no value => no value
Native OpenSSL support => enabled

openssl version
OpenSSL 1.0.1f 6 Jan 2014

抛出异常

project-root路径/供应商/yiisoft/yii2-httpclient/src/streamtransport.php的文件位置

   public function send($request)
{
    $request->beforeSend();

    $request->prepare();

    $url = $request->getFullUrl();
    $method = strtoupper($request->getMethod());

    $contextOptions = [
        'http' => [
            'method' => $method,
            'ignore_errors' => true,
        ],
        'ssl' => [
            'verify_peer' => false,
        ],
    ];

    $content = $request->getContent();
    if ($content !== null) {
        $contextOptions['http']['content'] = $content;
    }
    $headers = $request->composeHeaderLines();
    $contextOptions['http']['header'] = $headers;

    $contextOptions = ArrayHelper::merge($contextOptions, $this->composeContextOptions($request->getOptions()));

    $token = $request->client->createRequestLogToken($method, $url, $headers, $content);
    Yii::info($token, __METHOD__);
    Yii::beginProfile($token, __METHOD__);

    try {
        $context = stream_context_create($contextOptions);
        $stream = fopen($url, 'rb', false, $context);
        $responseContent = stream_get_contents($stream);
        // see http://php.net/manual/en/reserved.variables.httpresponseheader.php
        $responseHeaders = $http_response_header;
        fclose($stream);
    } catch (\Exception $e) {
        Yii::endProfile($token, __METHOD__);
        throw new Exception($e->getMessage(), $e->getCode(), $e); // this is line number 63 
    }

    Yii::endProfile($token, __METHOD__);

    $response = $request->client->createResponse($responseContent, $responseHeaders);

    $request->afterSend($response);

    return $response;
}

enter image description here
I’ve been trying to log in using Gmail on my website. but I'm getting "stream_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000126:SSL routines::unexpected eof while reading"
Website is build on yii2 and hosted on the nginx server on the aws ubuntu.

php -i | grep -i openssl
SSL Version => OpenSSL/3.0.2
libSSH Version => libssh/0.9.6/openssl/zlib
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 3.0.2 15 Mar 2022
OpenSSL Header Version => OpenSSL 3.0.2 15 Mar 2022
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => /usr/lib/ssl/cert.pem => /usr/lib/ssl/cert.pem
openssl.capath => no value => no value
Native OpenSSL support => enabled

openssl version
OpenSSL 1.0.1f 6 Jan 2014

location of file which throwing the exception

project-root-path/vendor/yiisoft/yii2-httpclient/src/StreamTransport.php at line 63

   public function send($request)
{
    $request->beforeSend();

    $request->prepare();

    $url = $request->getFullUrl();
    $method = strtoupper($request->getMethod());

    $contextOptions = [
        'http' => [
            'method' => $method,
            'ignore_errors' => true,
        ],
        'ssl' => [
            'verify_peer' => false,
        ],
    ];

    $content = $request->getContent();
    if ($content !== null) {
        $contextOptions['http']['content'] = $content;
    }
    $headers = $request->composeHeaderLines();
    $contextOptions['http']['header'] = $headers;

    $contextOptions = ArrayHelper::merge($contextOptions, $this->composeContextOptions($request->getOptions()));

    $token = $request->client->createRequestLogToken($method, $url, $headers, $content);
    Yii::info($token, __METHOD__);
    Yii::beginProfile($token, __METHOD__);

    try {
        $context = stream_context_create($contextOptions);
        $stream = fopen($url, 'rb', false, $context);
        $responseContent = stream_get_contents($stream);
        // see http://php.net/manual/en/reserved.variables.httpresponseheader.php
        $responseHeaders = $http_response_header;
        fclose($stream);
    } catch (\Exception $e) {
        Yii::endProfile($token, __METHOD__);
        throw new Exception($e->getMessage(), $e->getCode(), $e); // this is line number 63 
    }

    Yii::endProfile($token, __METHOD__);

    $response = $request->client->createResponse($responseContent, $responseHeaders);

    $request->afterSend($response);

    return $response;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情域 2025-02-12 03:55:36

刚刚开始遇到这个问题,经过一项研究,这似乎是OpenSSL lib的问题: https://bugs.php.net/bug.php?id=79589

php 8.1.7已经对此进行了修复,因此更新您的PHP可能应该解决此问题:
https://www.php.net/changelog-8.php#8.1。 7

Just started having this issue too, after some research this appears to be an issue with the OpenSSL Lib: https://bugs.php.net/bug.php?id=79589

PHP 8.1.7 already ships with a fix for this, so updating your PHP should probably fix this:
https://www.php.net/ChangeLog-8.php#8.1.7

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文