file_get_contents()无法正常使用youtube

Muh*_*man 5 php ssl

我想从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
Run Code Online (Sandbox Code Playgroud)

上述错误是什么意思?

什么是 SSL: crypto enabling timeout

Dav*_*ris 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);
Run Code Online (Sandbox Code Playgroud)