Search code examples
google-drive-apigoogle-docsgoogle-api-php-clientgoogle-workspacegoogle-docs-api

503 error when trying to get google doc with many pages


I am facing an issue with Google Drive API. I am using PHP (version 8.1.27) with the Symfony framework (version 6.4.*) on Ubuntu ( version 22.04.3 LTS). I incorporated the latest Google API library (version 2.15.3).

I have no issues when retrieving files with less pages (300-400 pages). But I have that one file that has about 950-1000 pages. When I try to get the file, I always end up in a 503 error. The code looks as follows:

        try {
        $service = new Docs($client);
        $doc = $service
            ->documents
            ->get($file->id);
        $drive = new Drive($client);
        $fileDetails = $drive->files->get($doc->getDocumentId(), ["fields" => "createdTime,modifiedTime"]);
    } catch (\Throwable $t) {
        error_log($t->getCode(), 0);
        error_log($t->getMessage(), 0);
        error_log($t->getTraceAsString(), 0);
    }

Whereas the message I get in return is as follows:

Connection refused for URI https://docs.googleapis.com/v1/documents/1SDq_m48Ctg***********
#0 /var/www/*****.com/vendor/google/auth/src/Middleware/AuthTokenMiddleware.php(117): GuzzleHttp\Handler\StreamHandler->__invoke()
#1 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): Google\Auth\Middleware\AuthTokenMiddleware->Google\Auth\Middleware\{closure}()
#2 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke()
#3 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#4 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/Middleware.php(63): GuzzleHttp\RedirectMiddleware->__invoke()
#5 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#6 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke()
#7 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/Client.php(107): GuzzleHttp\Client->transfer()
#8 /var/www/*****.com/vendor/guzzlehttp/guzzle/src/Client.php(124): GuzzleHttp\Client->sendAsync()
#9 /var/www/*****.com/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php(47): GuzzleHttp\Client->send()
#10 /var/www/*****.com/vendor/google/apiclient/src/Http/REST.php(84): Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke()
#11 [internal function]: Google\Http\REST::doExecute()
#12 /var/www/*****.com/vendor/google/apiclient/src/Task/Runner.php(187): call_user_func_array()
#13 /var/www/*****.com/vendor/google/apiclient/src/Http/REST.php(66): Google\Task\Runner->run()
#14 /var/www/*****.com/vendor/google/apiclient/src/Client.php(926): Google\Http\REST::execute()
#15 /var/www/*****.com/vendor/google/apiclient/src/Service/Resource.php(238): Google\Client->execute()
#16 /var/www/*****.com/vendor/google/apiclient-services/src/Docs/Resource/Documents.php(91): Google\Service\Resource->call()
#17 /var/www/*****.com/src/Service/Google/DocsApiService.php(59): Google\Service\Docs\Resource\Documents->get()
#18 /var/www/*****.com/src/Command/GranularAudience/ImportDocsCommand.php(83): App\Service\Google\DocsApiService->getLinkedCustomListStructure()
#19 /var/www/*****.com/vendor/symfony/console/Command/Command.php(326): App\Command\GranularAudience\ImportDocsCommand->execute()
#20 /var/www/*****.com/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
#21 /var/www/*****.com/vendor/symfony/framework-bundle/Console/Application.php(126): Symfony\Component\Console\Application->doRunCommand()
#22 /var/www/*****.com/vendor/symfony/console/Application.php(324): Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand()
#23 /var/www/*****.com/vendor/symfony/framework-bundle/Console/Application.php(80): Symfony\Component\Console\Application->doRun()
#24 /var/www/*****.com/vendor/symfony/console/Application.php(175): Symfony\Bundle\FrameworkBundle\Console\Application->doRun()
#25 /var/www/*****.com/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php(49): Symfony\Component\Console\Application->run()
#26 /var/www/*****.com/vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run()
#27 /var/www/*****.com/bin/console(11): require_once('...')
#28 {main}

Did anybody else ever face this issue? I just can't get it working - except for deleting hundreds of pages, which makes the get call work. But since we need all of the pages in that document, this is not really a feasible workaround.

Edit1: The file I am trying to get here is not very large as well. It has many pages yes, but the size of the file is just about 550-600 KB.


Solution

  • Found the issue. I do not know why I saw a 500 error in the logs, suggesting that an error from Google side happened, but on my side I had to raise the default_socket_timeout in my php.ini from 30 to a higher value. In my case, Google's server needed about 180 seconds to respond, so I put that timeout to 300 now.