Google drive file upload using Service account of

I want to save the file to Google Drive from the php site. For this, I’m using the Api Key (in JSON form) of Service Accounts in the Google developer console Apis & Services to upload files in in Drive folder.
Now the problem is that It takes 8 to 9 seconds to upload files to drive, no matter how fast your internet connection is. I want to optimize it so that It will completely depend on the network speed. In the PHP site, I am using (composer require Google/apiclient:^2.15).

(Upload File)
function uploadFiles($file, $folderName, $fileName, $driveId )
{
try {
    set_time_limit(60);
    $client = new Google_Client();
    putenv('GOOGLE_APPLICATION_CREDENTIALS=./api_key.json');
    $client->useApplicationDefaultCredentials();
    $client->addScope(Drive::DRIVE);
    $driveService = new Drive($client);
    $existingFolder = getFolderByName($driveService, $folderName, $driveId);
    if ($existingFolder) {
        $existingFile = getFileByName($driveService, $fileName, $existingFolder->id);
        if ($existingFile) {
            if (deleteFile($driveService, $existingFile->id)) {
                return uploadFile($driveService, $file, $fileName, $existingFolder->id);
            } else {
                return null;
            }
        } else {
            return uploadFile($driveService, $file, $fileName, $existingFolder->id);
        }
    } else {
        $createdFolder = createFolder($driveService, $folderName, $driveId);
        if ($createdFolder) {
            return uploadFile($driveService, $file, $fileName, $createdFolder);
        } else {
            return null;
        }
    }
} catch (Exception $ex) {
    return 100;
  }
}
(Get Folder Name)
function getFolderByName($driveService, $folderName, $parentFolderId = null)
{
    $query = "name = '$folderName'";
    if ($parentFolderId) {
    $query .= " and '$parentFolderId' in parents";
    }
    $response = $driveService->files->listFiles([
        'q' => $query,
        'fields' => 'files(id)'
    ]);
    if (count($response->files) > 0) {
        return $response->files[0];
    } else {
        return null;
    }
}

(Get File Name)
function getFileByName($driveService, $fileName, $folderId = null)
{
    try {
        $params = [
            'q' => "name='$fileName'",
        ];

        if ($folderId) {
            $params['q'] .= " and '$folderId' in parents";
        }

        $results = $driveService->files->listFiles($params);

        if (count($results->getFiles()) > 0) {
            return $results->getFiles()[0];
        } else {
            return null; // File not found
        }
    } catch (Exception $e) {
        return null; // Error occurred
    }
}

(Delet File If Already Exists)
function deleteFile($driveService, $fileId)
{
    try {
        $driveService->files->delete($fileId);
        return $fileId;
    } catch (Exception $ex) {
        echo "Error deleting file: " . $ex->getMessage();
        return null;
    }
}

(Upload File to Drive)
function uploadFile($driveService, $file, $fileName, $folderId = null)
{
    $filePath = $file['tmp_name'];
    $mimeType = mime_content_type($filePath);
    $fileMetadata = new DriveDriveFile([
        'name' => $fileName,
        'parents' => [$folderId]
    ]);
    // $fileMetadata = new DriveDriveFile([
    //     'name' => $fileName,
    // ]);

    // if ($folderId) {
    //     $fileMetadata->setParents([$folderId]);
    // }
    $content = file_get_contents($filePath);
    $file = $driveService->files->create(
        $fileMetadata,
        array(
            'data' => $content, // Removed the square brackets
            'mimeType' => $mimeType,
            'uploadType' => 'multipart',
            'fields' => 'id'
        )
    );
    return $file->id;
}

(Create Folder If not exists)
function createFolder($driveService, $folderName, $parentFolderId = null)
{
    // Check if the folder already exists
    $existingFolder = getFolderByName($driveService, $folderName, $parentFolderId);

    if ($existingFolder) {
        return $existingFolder->id;
    }
    $folderMetadata = new DriveDriveFile([
        'name' => $folderName,
        'mimeType' => 'application/vnd.google-apps.folder'
    ]);

    if ($parentFolderId) {
        $folderMetadata->setParents([$parentFolderId]);
    }

    $folder = $driveService->files->create($folderMetadata, [
        'fields' => 'id'
    ]);

    return $folder->id;
}

I want to fix the Time it is taking while uploading file to drive.
I’ve tested it on each part one by one, It is taking 9 seconds to uploadFile($driveService, $file, $fileName, $folderId = null) only,, For the first time when no folder is created on drive its creates folder and save file , from here problem starts where it takes that much time