Quote:
is it possible to send multiple uploads simultaneously (async/parallel)
- yes, it is but in my opinion, using parallel uploads in PHP with Google Drive API can be quite complex. I know that you can use PHP libraries or frameworks that support asynchronous operations, such as ReactPHP or Swoole or maybe use other languages like Node.js or Golang that has libraries for this.
To upload your files and wait for each to complete before starting the next in your loop, I will drop the defer option and make synchronous requests instead of asynchronous ones -
foreach ($files as $fileData) {
$file = new Google\Service\Drive\DriveFile();
$file->name = $fileName;
$chunkSizeBytes = 1 * 1024 * 1024;
$media = new Google\Http\MediaFileUpload($client, $file, $type, null, true, $chunkSizeBytes);
$media->setFileSize($size);
$handle = fopen($filePath, "rb");
while (!$media->isFinished()) {
$chunk = readVideoChunk($handle, $chunkSizeBytes);
$media->nextChunk($chunk);
}
$result = $media->getResult();
fclose($handle);
if ($result != false) {
}
}