file_get_contents()无法正常使用youtube

时间:2012-12-31 09:59:07

标签: ssl php

我想从youtube获取数据,而我正在使用file_get_contents()方法。

有时它工作正常但有时它不起作用并显示以下错误

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

上述错误是什么意思?

什么是SSL: crypto enabling timeout

3 个答案:

答案 0 :(得分:5)

由于SSL,您有时不能。使用cURL

这应该足够了:

$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);

答案 1 :(得分:0)

您看到的错误是您连接的服务器与系统上的SSL库之间不兼容。

请检查您使用的OpenSSL库是否过时。要验证这一点,您可能需要联系您的系统管理员。

如果curl库使用相同的SSL库,那么David Harris建议的解决方法也不起作用。

或者您可以尝试显式TLS1,这有时可行。我建议先在命令行上进行测试,例如使用命令行版本的curl

另外,您可能需要查看https://包装器(the SSL context options in PHPDocs旁边)使用的HTTP onesDocs

答案 2 :(得分:-2)

此错误意味着执行php页面的时间已经结束。默认情况下,php模块设置30秒执行任何php页面。您可以使用

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

请在php页面的开头写这个函数,并根据需要设置时间。它将覆盖php为该特定页面设置的默认执行时间。