Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gRPC library is installed but doesn't work

I'm having a error with google Firestore PHP Api, when I try to connect to Firestore the server return me this error: The requested client requires the gRPC extension. Please see https://cloud.google.com/php/grpc for installation instructions. The error comes from vendor/google/cloud/Core/src/ClientTrait.php because the function isGrpLoaded response with a false:

/**
 * Abstract the checking of the grpc extension for unit testing.
 *
 * @codeCoverageIgnore
 * @return bool
 */
protected function isGrpcLoaded()
{
    return extension_loaded('grpc');
}

I already installed gRPC following this instructions from google https://cloud.google.com/php/grpc. I install PECL, install Composer, install the gRPC extension, add the grpc extension to php.ini file, install the Protobuf Runtime library and also add the protobuf extension to php.ini.

So in my composer I have this lines:

...
google/grpc-gcp                       0.1.3    gRPC GCP library for channel management
google/protobuf                       v3.6.1   proto library for PHP
grpc/grpc                             1.15.0   gRPC library for PHP
...

In my php.ini file I have this two new lines:

extension=protobuf.so
extension=grpc.so

The problem comes here, when I execute in my server terminal this line:

sudo php -r "echo extension_loaded('grpc') ? 'yes' : 'no';"

the server response me with a yes, everything seems fine.

But if I create an php file like this:

<?php
  echo extension_loaded('grpc') ? 'yes' : 'no';
?>

The response is no.

I'm using

Ubuntu 16.04.5 LTS 
PHP 7.2.13
like image 506
dieroste Avatar asked Dec 19 '18 22:12

dieroste


People also ask

How do I install the gRPC runtime?

For most languages, the gRPC runtime can now be installed in a single step via native package managers such as npm for Node.js, gem for Ruby and pip for Python. Even though our Node, Ruby and Python runtimes are wrapped on gRPC’s C core, users now don’t need to explicitly pre-install the C core library as a package in most Linux distributions.

What's new in the gRPC update?

Today we are happy to provide an update that significantly simplifies the getting started experience for gRPC. For most languages, the gRPC runtime can now be installed in a single step via native package managers such as npm for Node.js, gem for Ruby and pip for Python.

Why can't I start the gRPC server on my Mac?

The ASP.NET Core gRPC template and samples use TLS by default. You'll see the following error message when you attempt to start the gRPC server: Unable to bind to https://localhost:5001 on the IPv4 loopback interface: 'HTTP/2 over TLS is not supported on macOS due to missing ALPN support.'.

Will gRPC Python release pre-compiled wheels for Windows?

There is an issue tracking this request #20615. gRPC Python is planning to release pre-compiled wheels to help Windows users build. Sorry, something went wrong. 1.26.0rc1 just went live with 3.8 binaries for both MacOS and Windows thanks to @lidizheng.


Video Answer


2 Answers

I found the error. The error was I edited the php.ini whats appers in Loaded Configuration File: /etc/php/7.2/cli/php.ini but I needed to edit the php.ini in Apache too, this file: /etc/php/7.2/apache2/php.ini

like image 132
dieroste Avatar answered Oct 19 '22 04:10

dieroste


If you're using Nginx and PHP FPM is running then php --ini may be outputting the wrong path of your ini file. You should use phpinfo() to check for the exact path.

In my case, having referenced php --ini, I was incorrectly updating /etc/php/7.2/cli/php.ini when the actual file was /etc/php/7.2/fpm/php.ini.

On updating the correct file and restarting FPM with systemctl restart php7.2-fpm.service phpinfo() output a section on gRPC.

like image 1
nick Avatar answered Oct 19 '22 04:10

nick