OpenSSL Error messages: error:14095126 unexpected eof while reading
OpenSSL Error messages: error:14095126 unexpected eof while reading
描述
此错误:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
returns 当:
$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设置为数组
$url = $links[$arrayindex];
禁用 SSL
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );
从url
获取文件
$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文件
中
我有一个类似的 problem.I 怀疑您正在使用 Xampp-Windows-7.4.5.In 那个案例 file_get_contents()
函数给出了 SSL 错误laravel.It 虽然在我这边适用于简单(核心)php。
您可以尝试的事情。
- 使用 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);
Disable/Uninstall Skpye.As skpye 使用端口 80/443(https),如果您在端口 80 上使用 apache,请尝试切换到端口 8080 或卸载 skpye,如果您不使用it.That 也可能会解决您的问题。
降级到Xampp-Windows-7.2.3如果你想使用file_get_contents()
function.This也解决了我的问题。
我 运行 也关注这个问题,并且能够更深入地跟进@Huzaifa99 的建议。
就我而言,我是 运行 Laravel 应用程序 PHP 7.4.5 Windows。 OpenSSL v1.1.1e 显然存在问题,可能只是 Windows。安装 PHP 7.4.6+ 的最新版本解决了我的问题。具体来说,替换文件 libssl-1_1-x64.dll
.
我在 Windows 10 上使用 php 7.4.9 和 apache v2.4.33 遇到了这个问题。
尽管我已将 php 更新到最新的 php 版本 (v.7.4.11),但问题仍然存在。
原来是apache自带的openssl v1.1.1e导致了这个错误。使用 openssl v1.1.1h 更新到 Apache v2.4.46 后问题解决了。
在我的例子中,我通过将 libssl-1_1-x64.dll dll 从 php 文件夹复制到 apache bin 文件夹
来解决它
我在 Windows 上遇到了同样的问题,我找到了以下信息:
https://www.php.net/manual/en/function.fopen.php#refsect1-function.fopen-notes
Warning
When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen() to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning.
我尝试临时设置 error_reporting(0);
,它对我有用,我收到了远程服务器的响应。
但我应该为我的情况使用其他解决方案。也许此信息会对某人有所帮助。
在 PHP 8.1.2 上,@SpecDrum 的解决方案的不那么残酷的版本对我有用。 OpenSSL 错误在 PHP 中表示为警告。所以忽略警告(暂时)就足够了:
$error_level = error_reporting();
error_reporting($error_level & ~E_WARNING);
描述
此错误:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
returns 当:
$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设置为数组
$url = $links[$arrayindex];
禁用 SSL
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );
从url
获取文件$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文件
我有一个类似的 problem.I 怀疑您正在使用 Xampp-Windows-7.4.5.In 那个案例 file_get_contents()
函数给出了 SSL 错误laravel.It 虽然在我这边适用于简单(核心)php。
您可以尝试的事情。
- 使用 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);
Disable/Uninstall Skpye.As skpye 使用端口 80/443(https),如果您在端口 80 上使用 apache,请尝试切换到端口 8080 或卸载 skpye,如果您不使用it.That 也可能会解决您的问题。
降级到Xampp-Windows-7.2.3如果你想使用
file_get_contents()
function.This也解决了我的问题。
我 运行 也关注这个问题,并且能够更深入地跟进@Huzaifa99 的建议。
就我而言,我是 运行 Laravel 应用程序 PHP 7.4.5 Windows。 OpenSSL v1.1.1e 显然存在问题,可能只是 Windows。安装 PHP 7.4.6+ 的最新版本解决了我的问题。具体来说,替换文件 libssl-1_1-x64.dll
.
我在 Windows 10 上使用 php 7.4.9 和 apache v2.4.33 遇到了这个问题。 尽管我已将 php 更新到最新的 php 版本 (v.7.4.11),但问题仍然存在。 原来是apache自带的openssl v1.1.1e导致了这个错误。使用 openssl v1.1.1h 更新到 Apache v2.4.46 后问题解决了。
在我的例子中,我通过将 libssl-1_1-x64.dll dll 从 php 文件夹复制到 apache bin 文件夹
来解决它我在 Windows 上遇到了同样的问题,我找到了以下信息: https://www.php.net/manual/en/function.fopen.php#refsect1-function.fopen-notes
Warning When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen() to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning.
我尝试临时设置 error_reporting(0);
,它对我有用,我收到了远程服务器的响应。
但我应该为我的情况使用其他解决方案。也许此信息会对某人有所帮助。
在 PHP 8.1.2 上,@SpecDrum 的解决方案的不那么残酷的版本对我有用。 OpenSSL 错误在 PHP 中表示为警告。所以忽略警告(暂时)就足够了:
$error_level = error_reporting();
error_reporting($error_level & ~E_WARNING);