[编辑]正如错误所指出的,我的 php.ini 为每个脚本分配 1GB 的 RAM(memory_limit = 1G),这应该绰绰有余,所以我不是在问如何增加或修改这个限制。我刚刚发现这个问题可以被认为是这个其他未回答问题的重复:Upload large file to google drive with PHP Client Library
我正在尝试使用google API 快速入门指南中提供的 PHP CLI 脚本从我的 VPS 将一个大文件 (237MB) 上传到我的 google drive 帐户,但出现以下错误:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted
(tried to allocate 316952783 bytes) in
/var/www/google-api-php-client/src/service/Google_MediaFileUpload.php on line 135
剧本:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
// Get your credentials from the APIs Console
$client->setClientId('MY_CLIENT_ID');
$client->setClientSecret('MY_CLIENT_SECRET');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($client);
$authUrl = $client->createAuthUrl();
//Request authorization
print "Please visit:\n$authUrl\n\n";
print "Please enter the auth code:\n";
$authCode = trim(fgets(STDIN));
// Exchange authorization code for access token
$accessToken = $client->authenticate($authCode);
$client->setAccessToken($accessToken);
//Insert a file
$file = new Google_DriveFile();
$file->setTitle('My zip file');
$file->setDescription('A test zip file');
$file->setMimeType('application/zip');
$data = file_get_contents('myfile.zip');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'application/zip',
));
print_r($createdFile);
?>
top 说我有 787816k 可用物理内存(加上 2G 缓存),所以我不知道问题出在哪里。有什么线索吗?