'Google Firebase admin SDK for PHP not working when fetching data from Firestore

I am trying to integrate Google Firebase admin SDK with a Laravel backend to handle the data in Firestore database. Details of my local environment are as below.

Ubuntu 20.04.3 LTS
GNU Make 4.1
gcc 9.3.0

PHP 7.4.27
PEAR 1.10.12
grpc 1.24.0 or 1.44.0
protobuf 3.19.4

Laravel 8.83.4
kreait/laravel-firebase 4.1.0

I have created a service account in Firebase project settings and have downloaded a private key in a JSON file. And set the path of it as the value of the below environment variable.

export GOOGLE_APPLICATION_CREDENTIALS="/home/vagrant/my-project/firebase-adminsdk.json"

Then I am using Laravel tinker to fetch a document from the Firestore database.

$db = new Google\Cloud\Firestore\FirestoreClient();
$docRef = $db->collection('users')->document('047gpiOlqGRlL6gUAnwwpVTzKiR2');
$snapshot = $docRef->snapshot();

But the above script hangs running on the last line of the above code block without returning a value or throwing an error nor an exception.

The same issue occurs in the testing server with below configurations

centos-release-7-9.2009.1.el7.centos.x86_64
GNU Make 4.2 gcc (GCC) 4.8.5

PHP 7.4.28
PEAR 1.10.13
grpc 1.24.0
protobuf 3.19.4

But if I downgrade the grpc to 1.4.0 in the testing server, I can successfully fetch a document from the Firestore database. But I cannot downgrade the grpc package in my local environment to a version below than 1.24.0.

I have already spent 2 days trying to find a solution for this, trying to install grpc 1.4.0, trying to downgrade the GNU Make, trying to downgrade the gcc. But nothing is successfully working.

Any help is extremely appreciated. Thank you!



Sources

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

Source: Stack Overflow

Solution Source