Reputation: 10946
I want to fetch data from youtube and I am using file_get_contents()
method.
sometime it works fine but sometime it do not works 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 does the above errors mean?
What is SSL: crypto enabling timeout
Upvotes: 5
Views: 3456
Reputation: 2190
This error means that the time for execution of php page has came to an end. By default php module sets 30 seconds for the execution of any php page. You can increase it using
ini_set('max_execution_time', time in seconds as per your need);
Please write this function at the starting of the php page and set the time as per your need. It will overwrite the default execution time set by php for that particular page.
Upvotes: -2
Reputation: 198209
The error you see is an incompatibility between the server you are connecting to and the SSL library you have on your system.
Please check that the OpenSSL library you're using is not outdated. To verify this you probably need to contact your system administrator.
If the curl library uses the same SSL library, the suggested workaround by David Harris does not work as well.
Alternatively you can try to explicitly TLS1, this sometimes works. I suggest to test on the commandline first, e.g. by using the commandline version of curl
.
Also you might want to take a look into the SSL context options in PHPDocs which are used by the the https://
wrapper (next to the HTTP onesDocs).
Upvotes: 0
Reputation: 2707
You can't sometimes, because of SSL. Use cURL
This should suffice:
$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);
Upvotes: 5