【问题标题】:PHP: file_get_contents(): SSL operation failed with code 1PHP:file_get_contents():SSL 操作失败,代码为 1
【发布时间】:2020-06-15 17:39:46
【问题描述】:

我最近开始使用 PHP 进行编程,并开始了我的新个人项目,这是一个基于 PHP 的新闻网站,可以围绕特定主题生成头条新闻。我正在使用 PHP 7.4.4、Bootstrap 和一点 CSS。一切进展顺利,任何错误都已解决,任何问题都通过搜索得到解答。至少在我开始将实际新闻插入我的网站之前。当我尝试使用我的 api 密钥(来自https://newsapi.org 的 API 密钥)将直播新闻插入“体育新闻”页面时,页面顶部出现错误:

file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14095126:SSL 例程:ssl3_read_n:读取 /opt/lampp/htdocs/news/app/views/news/sportNews.php 时出现意外 eof在第 18 行

该消息确实显示在我的屏幕上,但即使在反复尝试修复错误之后,错误仍然没有改变。

这是我的 sportNews.php:

<?php $this->setSiteTitle('News'); ?>
<?php $this->start('body'); ?>
<head>
  <link href="css/newscss.css" rel="stylesheet"></link>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
  <?php
    //API_KEY filled in when running program
    $url = "https://newsapi.org/v2/everything?q=sports&apiKey=API_KEY";
    $response = file_get_contents($url);  //ERROR LINE
    $NewsData = json_decode($response);
  ?>
  <div class="jumbotron">
    <h1>Sports News</h1>
  </div>
  <div class="container-fluid">
    <?php
    foreach($NewsData->articles as $News)
    {
    ?>
    <div class="row">
      <div class="col-md-3">
        <img src="<?php echo $News->urlToImage ?>" alt="News thumbnail">
      </div>
      <div class="col-md-9">
        <h2>Title: <?php echo $News->title ?></h2>
        <h5>Description: <?php echo $News->description ?></h5>
        <p>Preview/Content: <?php echo $News->content ?></p>
        <h6>Author: <?php echo $News->author ?></h6>
        <h6>Published <?php echo $News->publishedAt ?></h6>
      </div>
      <?php
      }
      ?>
    </div>
  </div>
</body>
<?php $this->end(); ?>

我已多次尝试修复此错误,包括测试类似堆栈溢出问题的答案,但都没有结果。经过彻底的搜索,我仍然没有结果,我决定问一个问题。任何帮助表示赞赏

【问题讨论】:

    标签: php api ssl


    【解决方案1】:

    当您的客户无法建立版本时会发生这种情况。当您拥有较旧的 PHP 版本和较新的 openssl 版本时,会发生该错误。在较新的版本中,您进行了一些制动更改,并且出现了该错误。

    https://github.com/dask/gcsfs/issues/246

    您可以尝试降级或升级您的 openssl 版本。该错误应该出现在版本 1.1.1e 中。所以先检查你的openssl版本,看看你是否可以升级它。

    OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_n', 'unexpected eof while reading')] when updating / searching / installing conda packages

    这是另一个对 yum 很有帮助的帖子。

    【讨论】:

      猜你喜欢
      • 2015-04-27
      • 2013-08-25
      • 2021-05-14
      • 1970-01-01
      • 2016-09-07
      • 2015-01-21
      • 2016-12-19
      • 2018-03-07
      • 1970-01-01
      相关资源
      最近更新 更多