bir*_*use 4 php youtube laravel
说明
此错误:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
Run Code Online (Sandbox Code Playgroud)
返回时:
$file = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Run Code Online (Sandbox Code Playgroud)
重现步骤
视频下载:
https://www.youtube.com/watch?v=r5NzAksjfDI
提取视频ID:
$video_id = $yt->extractVideoId(implode($url));
Run Code Online (Sandbox Code Playgroud)
获取可下载的网址
$links = $yt->getDownloadLinks($video_id, $selector = 'video');
Run Code Online (Sandbox Code Playgroud)
获取指定视频质量等的数组键。
$arrayindex = array_search('mp4, video, 1080p, audio', array_column($links, 'format'));
Run Code Online (Sandbox Code Playgroud)
将 $url 设置为数组
$url = $links[$arrayindex];
Run Code Online (Sandbox Code Playgroud)
禁用 SSL
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );
Run Code Online (Sandbox Code Playgroud)
从url获取文件
$video = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Run Code Online (Sandbox Code Playgroud)
将视频发送回前端
return view('convert', [ 'url' => $url['url'], 'quality' => $url['format'], ]);
Run Code Online (Sandbox Code Playgroud)
预期行为:
视频被下载
实际行为:
我收到此错误:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
Run Code Online (Sandbox Code Playgroud)
代码停止。
版本
最新版本:https :
//github.com/Athlon1600/youtube-downloader/blob/master/src/YouTubeDownloader.php
附加信息
此代码在 Laravel 框架中,这里的代码在 UrlController 中。这是本地开发服务器,禁用防火墙时也会显示此错误。我的代码中使用的所有函数都在 YouTubeDownloader.php 文件中
我有一个类似的问题。我怀疑你使用的是 Xampp-Windows-7.4.5。在这种情况下,file_get_contents()函数在 laravel 上给出了 SSL 错误。不过它在我这边的简单(核心)php 上工作。
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;
}
Run Code Online (Sandbox Code Playgroud)
然后你可以像这样调用函数。
$data = file_get_content_curl($url);
$save = file_put_contents($path, $data);
Run Code Online (Sandbox Code Playgroud)
禁用/卸载 Skpye。由于 skpye 使用端口 80/443(https),如果您在端口 80 上使用 apache,请尝试切换到端口 8080 或卸载 skpye(如果您不使用它)。这也可能会解决您的问题。
如果您想使用file_get_contents()功能,请降级到 Xampp-Windows-7.2.3 。这也为我解决了问题。
我也遇到了这个问题,并且能够更深入地跟进@Huzaifa99 的建议。
就我而言,我在 Windows 上使用 PHP 7.4.5 运行 Laravel 应用程序。OpenSSL v1.1.1e 显然存在问题,可能只是 Windows。安装最新版本的 PHP 7.4.6+ 修复了我的问题。具体来说,替换文件libssl-1_1-x64.dll.
| 归档时间: |
|
| 查看次数: |
3013 次 |
| 最近记录: |