Description
This error:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
returns when:
$file = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Steps to Reproduce
Video to download:
https://www.youtube.com/watch?v=r5NzAksjfDI
Extract the video id:
$video_id = $yt->extractVideoId(implode($url));
Get the downloadable url
$links = $yt->getDownloadLinks($video_id, $selector = 'video');
Get the array key for the specified video quality etc.
$arrayindex = array_search('mp4, video, 1080p, audio', array_column($links, 'format'));
Set $url to array
$url = $links[$arrayindex];
Disable SSL
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );
Get the file from the url
$video = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Send the video back to front end
return view('convert', [ 'url' => $url['url'], 'quality' => $url['format'], ]);
Expected behavior:
The video gets downloaded
Actual behavior:
I get this error:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
The code stops.
Version
The latest version of:
https://github.com/Athlon1600/youtube-downloader/blob/master/src/YouTubeDownloader.php
Additional Information
This code is in the laravel framework, the code here is in the UrlController. This is a local development server, this error also shows up when the firewall is disabled. All the functions used in my code are in the YouTubeDownloader.php file
Advertisement
Answer
I ran into this issue as well and was able to follow up a little deeper into @Huzaifa99’s recommendations.
In my case, I was running a Laravel app with PHP 7.4.5 on Windows. There is apparently an issue with OpenSSL v1.1.1e, possibly just with Windows. Installing the latest build of PHP 7.4.6+ fixed my issues. Specifically, the replacing the file libssl-1_1-x64.dll
.