我使用PHP通过直接上传将视频发送到Youtube。它工作正常的更小尺寸的影片,但试图发送一个390 MB的视频时,我得到以下错误:通过Youtube API上传大视频导致内存不足
PHP Fatal error: Out of memory (allocated 3932160) (tried to allocate 390201902 bytes)
我试过增加memory_limit
但这并不能帮助。
if ($isFile) {
ini_set('memory_limit', '2G')
$data = file_get_contents($data);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($ch);
curl_close($ch);
return $out;
我也通过exec()
试图运行卷曲后来甚至怪异的事情发生了:
curl http://uploads.gdata.youtube.com/feeds/api/users/default/uploads -H 'POST /feeds/api/users/default/uploads HTTP/1.1' -H 'Host: uploads.gdata.youtube.com' -H 'Authorization: OAuth [snip oauth info]"' -H 'GData-Version: 2' -H 'X-GData-Client: www.mywebsite.com' -H 'X-GData-Key: key=[snip]' -H 'Slug: video.AVI' -H 'Content-Type: multipart/related; boundary="iUI5C0hzisAHkx9SvaRJ"' -H 'Content-Length: 390193710' -H 'Connection: close' -d /tmp/youtube.xml
/tmp/youtube.xml是我已经保存的数据文件进行上传。也许这种用法是错误的?
所以它看起来像正在发送的文件,但后来我得到一个空的回复这将需要大约6分钟
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
...
0 0 0 0 0 0 0 0 --:--:-- 0:06:00 --:--:-- 0
curl: (52) Empty reply from server
编辑:
我使用OAuth,所以我不能正常使用的这个PHP API库。我必须上传一个XML文件,其中包含XML文件中包含的视频的二进制数据:outlined here
I found another person with the same problem谁提供了读取和发送文件的代码块。但是,当尝试使用这种方法时,Youtube将返回一个411页面,表示需要“Content-Length”标题。我正在设置内容长度标题,所以这可能是一个错误。此方法使用fsockopen()
函数而不是cURL。 [其实,再次查看代码,我意识到我只是用“\ n”而不是“\ r \ n”来分隔标题。这可能是问题。我会尝试用回车以及]
编辑2:
我觉得“\ r \ n”个工作,但现在的代码,我再次收到从Youtube空回复。
任何卷曲专家在那里,可以帮助我得到这个工作?我完全被这个难住了。
)感谢您的回复,我编辑了我的问题以提供更多信息。 – 2010-01-25 16:17:54
美丽!它的工作原理!我想我得到了空的答复,因为我没有在最终边界之后的“\ r \ n”。打开了这个问题的赏金,并授予你编辑你的答案和提供代码。我需要一段时间才能找出它。 – 2010-01-28 07:35:08
@MattMcCormick你会发布你的完整代码吗?我正在尝试上传一个很大的文件,但不能得到它的工作 – J888 2013-06-09 09:21:13