Warm tip: This article is reproduced from serverfault.com, please click

php-OpenSSL错误消息:读取时出现错误:14095126意外EOF

(php - OpenSSL Error messages: error:14095126 unexpected eof while reading)

发布于 2020-05-06 12:33:54

说明
此错误:

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading

在以下情况下返回:

$file = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));

重现步骤

视频下载:


https://www.youtube.com/watch?v=r5NzAksjfDI

提取视频ID:

$video_id = $yt->extractVideoId(implode($url));

获取可下载的URL

$links = $yt->getDownloadLinks($video_id, $selector = 'video');

获取指定视频质量等的阵列键。

$arrayindex = array_search('mp4, video, 1080p, audio', array_column($links, 'format'));

将$ url设置为array

$url = $links[$arrayindex];

停用SSL

$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );

从网址获取文件

$video = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));

将视频发送回前端

return view('convert', [ 'url' => $url['url'], 'quality' => $url['format'], ]);

预期行为:
视频已下载
实际行为:

我收到此错误:

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading

代码停止。

版本
最新版本:https :
//github.com/Athlon1600/youtube-downloader/blob/master/src/YouTubeDownloader.php

附加信息
此代码在laravel框架中,此处的代码在UrlController中。这是本地开发服务器,禁用防火墙后也会显示此错误。我的代码中使用的所有功能都在YouTubeDownloader.php文件中

Questioner
hoofdtelefoon
Viewed
0
Huzaifa 2020-06-02 21:48:52

我有一个类似的问题。我怀疑你正在使用Xampp-Windows-7.4.5。在这种情况下,file_get_contents()函数在laravel上给出了SSL错误。

你可以尝试的事情。

  1. 使用Curl而不是。file_get_contents()你可以创建一个自定义函数,该函数将以相同的方式(启用SSL)运行。
function file_get_content_curl ($url) 
{
    // Throw Error if the curl function does'nt exist.
    if (!function_exists('curl_init'))
    { 
        die('CURL is not installed!');
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

然后,你可以像这样调用该函数。

$data = file_get_content_curl($url);
$save = file_put_contents($path, $data);
  1. 禁用/卸载Skpye。由于skpye使用端口80/443(https),如果你在端口80上使用apache,请尝试切换到端口8080或如果不使用它请卸载skpye。这也可能解决了你的问题。

  2. 如果要使用file_get_contents()功能,请降级到Xampp-Windows-7.2.3,这也为我解决了这个问题。