Php 通过Youtube Api v3发送视频会导致服务器冻结
我想创建一个网站,用户可以在上面向Youtube发送视频 使用Google文档,我编写了以下代码:Php 通过Youtube Api v3发送视频会导致服务器冻结,php,youtube-api,Php,Youtube Api,我想创建一个网站,用户可以在上面向Youtube发送视频 使用Google文档,我编写了以下代码: $youtube = new \Google_Service_YouTube($this->client); // REPLACE this value with the path to the file you are uploading. $videoPath = $movieEntity->getAbsoluteMoviePath();
$youtube = new \Google_Service_YouTube($this->client);
// REPLACE this value with the path to the file you are uploading.
$videoPath = $movieEntity->getAbsoluteMoviePath();
// Create a snippet with title, description, tags and category ID
// Create an asset resource and set its snippet metadata and type.
// This example sets the video's title, description, keyword tags, and
// video category.
$snippet = new \Google_Service_YouTube_VideoSnippet();
$snippet->setTitle( $movieEntity->getTitle() );
$snippet->setDescription( $movieEntity->getDescription() );
$snippet->setTags( $movieEntity->getTags() );
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
$snippet->setCategoryId("22");
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new \Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
// Associate the snippet and status objects with a new video resource.
$video = new \Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Specify the size of each chunk of data, in bytes. Set a higher value for
// reliable connection as fewer chunks lead to faster uploads. Set a lower
// value for better recovery on less reliable connections.
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$this->client->setDefer(true);
// Create a request for the API's videos.insert method to create and upload the video.
$insertRequest = $youtube->videos->insert("status,snippet", $video);
// Create a MediaFileUpload object for resumable uploads.
$media = new \Google_Http_MediaFileUpload(
$this->client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$filesize = filesize($videoPath);
$media->setFileSize($filesize);
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$this->client->setDefer(false);
它工作正常,但在传输过程中,我的服务器被完全冻结——直到传输结束,我无法打开任何其他网站子页面。我在我的本地机器和专用服务器上进行了尝试,但我不知道这有什么问题
你能给我一些建议吗
致意