File_get_contents () does not work correctly with youtube

I want to get data from youtube, and I use the file_get_contents() method.

Once it works fine, but sometimes it doesn't work and shows the following error

 file_get_contents() [function.file-get-contents]: SSL: crypto enabling timeout file_get_contents() [function.file-get-contents]: Failed to enable crypto file_get_contents(https://gdata.youtube.com/feeds/api/users/default?access_token=token&v=2&alt=json) [function.file-get-contents]: failed to open stream: operation failed Maximum execution time of 30 seconds exceeded 

What do the above errors mean?

What is SSL: crypto enabling timeout

+5
source share
3 answers

You cannot sometimes because of SSL. Use cURL

That should be enough:

 $ch = curl_init('https://youtube.com'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20121230 Firefox/20.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); echo curl_exec($ch); 
+5
source

The error you see is incompatibility between the server you are connecting to and the SSL library that you use on your system.

Make sure the OpenSSL library you are using is not out of date. To verify this, you may need to contact your system administrator.

If the curl library uses the same SSL library, the proposed David Harris solution also does not work.

Alternatively, you can try explicitly TLS1, this sometimes works. I suggest first checking on the command line, for example. using curl command line version.

You can also take a look at the SSL context parameters in PHP Docs , which use the https:// wrapper (next to the HTTP Docs tags ).

0
source

This error means that the php page execution time has come to an end. By default, the php module sets 30 seconds to execute any php page. You can increase it using

 ini_set('max_execution_time', time in seconds as per your need); 

Please write this function when launching the php page and set the time according to your needs. It will overwrite the default runtime set by php for this particular page.

-2
source

All Articles