'Firestore with PHP - Google\Cloud\Core\Exception\[DeadlineExceededException|ServiceException]

I'm running a PHP project with theses dependencies :

{
    "require": {
        "slim/slim": "^3.9.2",
        "php": "^8.0.0",
        "slim/psr7": "^1.5",
        "google/cloud-firestore": "^1.20",
        "grpc/grpc": "^1.42",
        "google/cloud": "^0.175.0"
    }
}

I wan't to fetch data from a firestore database.

my php code :

<?php
session_start();

require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

$conf = [
    "keyFilePath" => __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'myfile.json'
];

use Google\Cloud\Firestore\FirestoreClient;

$db = new FirestoreClient($conf);
$user = $db->collection("users")->where('email', '=', "an-email")->documents();

I've tried many tutorials and the official doc but i've theses errors randomely. In many cases (80%) :

Type: Google\Cloud\Core\Exception\ServiceException
Code: 14
Message: { "message": "failed to connect to all addresses", "code": 14, "status": "UNAVAILABLE", "details": [] }
File: /users/home/arnoux23u/www/charlemiapp/charlemiapp-auth/vendor/google/cloud/Core/src/GrpcRequestWrapper.php
Line: 257

and in some other cases :

Type: Google\Cloud\Core\Exception\DeadlineExceededException
Code: 4
Message: { "message": "Deadline Exceeded", "code": 4, "status": "DEADLINE_EXCEEDED", "details": [] }
File: /users/home/arnoux23u/www/charlemiapp/charlemiapp-auth/vendor/google/cloud/Core/src/GrpcRequestWrapper.php
Line: 257

I don't know what's the problem. The app is running fine on NodeJS.

I precise that I'm not the owner of the machine which host the app. The webmaster has installed grpc extension (1.43.0).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source