Search code examples
phpgrpchttp-status-code-500classnotfound

grpc example php, “Class 'Grpc\ChannelCredentials' not found.” when oppening from browser, works from terminal


I have the following problem:

I installed grpc and got the given example (https://grpc.io/docs/languages/php/quickstart/) to work with PHP from the terminal (Windows PowerShell) running the run_greeter_client.sh file (as well as the same file using the changes the link mentions to send two 'Hello World' messages instead of one). I have also added the extension=grpc.so to the php.ini file, so I can even run it from the terminal using the instruction "php greeter_client.php". I use the node .\greeter_server.js instruction to run the server. Instead, when I try to run the php file from the browser it shows that I have an HTTP ERROR 500, and when I checked the logs I found the following:

PHP Fatal error:  Uncaught Error: Class 'Grpc\ChannelCredentials' not found 
in D:\MAMP\grpc\grpc\examples\php\greeter_client.php:30
Stack trace:
#0 D:\MAMP\grpc\grpc\examples\php\greeter_client.php(50): 
greet('localhost:50051', 'world')
#1 {main}
  thrown in D:\MAMP\grpc\grpc\examples\php\greeter_client.php on line 30

It seems strange because when I run it from the PowerShell (terminal) with the PHP command it runs properly and shows the 2 'Hello World' messages but from the browser that problem appears (using the same node js server from another PowerShell). Do you have any idea about what the problem could be?

Thank you very much, please do not close the issue if you need more details about the problem, I can provide any information you ask about it, just leave a comment.


Solution

  • I finally solved the problem, whenever I run the file from the terminal there is a specific location for the php.ini file it uses, which I had already changed to include the grpc extension. Although, I was wrong about the location of the php.ini file that is used when I run it from the browser. In case you face a similar issue, you can consult the phpinfo page from your browser and find the php.ini file in the path the "Loaded Configuration File" field indicates. Thank you!