我嘗試使用API V3將大文件以PHP格式上傳到Youtube。 我剛剛複製了官方代碼from there。使用YouTube官方可恢復視頻上傳的內存泄露PHP API V3
它適用於小型上傳(< 100Mo)。 但是當我嘗試上傳大文件,它返回:
Fatal error: Out of memory (allocated 102760448) (tried to allocate 1048577
bytes) in /homepages/40/d216486693/htdocs/uploadsys.php on line 143
我使用的代碼只是下方,線143是$chunk = fread($handle, $chunkSizeBytes);
我的服務器就可以允許一些更多的內存,但如果我嘗試上傳 GB大小文件? 實際上,主要的問題是,如果我在循環過程中檢查內存使用情況,並且發送塊大小爲&,它永遠不會減少!
就好像每塊都留在內存中......我該怎麼辦?試圖未成功地設置$ chunk
$snippet = new Google_Service_YouTube_VideoSnippet();
$filtre1 = array("'","'","'","\'");
$snippet->setTitle(str_replace("\\","",str_replace($filtre1,"’",$title)));
$snippet->setDescription("Descr");
$snippet->setTags(explode(",",$keywords));
$snippet->setCategoryId($ytcat);
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "unlisted";
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$insertRequest = $youtube->videos->insert("status,snippet", $video);
$media = new Google_Http_MediaFileUpload($client,$insertRequest,'video/*',null,true,$chunkSizeBytes);
$file_size = filesize($videofile);
$media->setFileSize($file_size);
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videofile, "rb");
$cc = 0;
while (!$status && !feof($handle)) {
//Line 143 below
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
$cc++;
}
fclose($handle);
我從您的問題中刪除了預先感謝。請參閱http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts – rene
介意發佈您的phpinfo()? –
您可能會在https://github.com/google/google-api-php-client/issues上報告更多的運氣。 – atastrumf