【发布时间】:2015-06-05 22:03:20
【问题描述】:
我在 php 中有一个函数可以通过一个独立的脚本上传几个文件,第一个文件上传正常,但最后一个 16GB 大约 20 分钟它会无缘无故地中断并且上传停止。身份验证已经处理,所以我不知道是什么导致了这个问题。这是它输出的代码和错误:
function insertFile($client,$service,$filePath,$name,$fId){
$file = new Google_Service_Drive_DriveFile();
$file->title = $name;
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($fId);
$file->setParents(array($parent));
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$request = $service->files->insert(
$file,
array(
'uploadType'=> 'resumable'
)
);
$finfo= finfo_open(FILEINFO_MIME_TYPE);
$media = new Google_Http_MediaFileUpload(
$client,
$request,
finfo_file($finfo, $filePath),
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($filePath));
$status = false;
$handle = fopen($filePath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
$result = false;
if($status != false) {
$result = $status;
}
fclose($handle);
$client->setDefer(false);
}
错误:
PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unape=resumable&upload_id=AEnB2UoRrzX46hJ02lIDkCJi03MFbE2KVP2LDCBOgnuiclONk3sBvSctZxW3NxsWt /libs/google-api-php-client/src/Google/IO/Stream.php
Stack trace:
#0 /libs/google-api-php-client/src/Google/IO/Abstract
#1 /libs/google-api-php-client/src/Google/Http/MediaF
#2 /root/name.php(199): Google_Http_MediaFileUpload->nextChunk(
#3 /root/name.php(102): insertFile(Object(Google_Client), /libs/google-api-php-client/src/Google/IO/Stream.php on l
【问题讨论】:
-
PHP 有一个允许的最大文件上传大小,请在您的
PHP.ini文件中检查。 -
问题是,我认为我没有上传。在 ini 中它说 2MB 限制,但我仍然可以达到 3 或 4GB 左右。虽然我是分块上传的,所以也许这就是我没有立即出错的原因。
-
我认为不是大小而是时间问题,发送服务器或接收服务器在 x 时间后关闭连接?很抱歉,我不能说在哪里可以找到这个变量。
-
我确实有 set_time_limit(0);对于执行时间,但问题的结果是它失败时大约是 20 分钟,所以它可能是一个设定的时间或一个设定的大小。
-
正如我所说,我目前不是专家,但我建议检查从服务器操作系统或到服务器操作系统是否有截止时间来切断传输。您的错误实际上是您有一个未捕获的异常 - 那么您可以破解一种输出核心异常值并查看它们是否阐明它的调试方法吗?
标签: php google-drive-api google-api-php-client