我想运行files.list以获取用户驱动器上的文件列表,然后并行运行files.get来下载文件。问题在于,当并行操作之前是对API的单个请求(files.list或files.get)时,Google客户端会在/ vendor / guzzlehttp / guzzle / src / Handler / CurlFactory中以“不受支持的操作数类型”中断.php第140行。
我正在将official Google PHP client和Amphp's parallelMap()一起使用。
我的代码如下:
function __construct($token, $refresh_token)
{
$google_client = new \Google_Client();
// ...........
$this->api = new \Google_Service_Drive($google_client);
}
public function downloadFile($remote_file_id)
{
$file = $this->api->files->get($remote_file_id, ['alt' => 'media']);
return $file->getBody()->getContents();
}
public function downloadFiles($files_ids)
{
$download_jobs = parallelMap($files_ids, function ($file_id) {
return $this->downloadFile($file_id);
});
return wait($download_jobs);
}
// $storage = new Storage(..., ...);
$files1 = [
0 => "1s9aaHl8UsTswPMsXAt6X_ooDY0idv27dfSR4ysWBI5J2KSuvqw",
1 => "1ZKQmozeA9TfUDp5dTs7CDuRcuesBhkK_iUe4XG3L1nE9ySRz6Q",
2 => "12kGcMS_l58cGJWvdOyQRLqwbbWhTHeA_OBuVITbeMcN0V0PnPA",
3 => "1ETVMmfno_DUn7KloyUpzukOFlt0QcinqZ0C2pRgff-osIHyf-Q",
4 => "1P6CIe7A8qsgLLHf3AZn0Gj4YsTHPsGIZRok0_Pke60QeAXGoMg",
5 => "1d8K7WvDqT40b1MGIDWMxK010invlmaX4e6qdc2pui7TV3Z4liQ",
];
$downloaded = $storage->downloadFile($files1[0]); // if uncommented, this causes downloadFiles to break
$downloaded = $storage->downloadFiles($files1);
似乎第一个请求对Google客户端内部执行了一些操作,然后并行请求停止工作。如果我只运行downloadFiles(),它将运行顺利。甚至可行:
$files = [];
$files[] = $storage->downloadFiles([$files1[0]]);
$files[] = $storage->downloadFiles([$files1[1]]);
$files[] = $storage->downloadFiles([$files1[2]]);
$files[] = $storage->downloadFiles([$files1[3]]);
我正在运行PHP 7.2.11