Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing gRPC for localhost

I'm working with PHP library of Google Cloud Firestore, it requires me to install and enable the gRPC extension.. I've read the guide which says

Windows users can download and enable DLLs from PECL. Support for Windows is experimental

In the PECL site I can see many links to tgz and DLL files but without any explanation of how to use or activate them in the XAMPP as a localhost

like image 214
MujtabaFR Avatar asked May 07 '18 21:05

MujtabaFR


3 Answers

I would like to add answer for 7.4.4 PHP Version,

I downloaded php_grpc-1.27.0-7.4-ts-vc15-x64.zip from this link https://windows.php.net/downloads/pecl/releases/grpc/1.27.0/

Then I copied pasted php_grpc.dll to C:\xampp\php\ext folder

In next step I opened php.ini under Dynamic extentions added extension=grpc

And then restarted and it was working fine.

like image 33
Ayaz Ali Shah Avatar answered Sep 19 '22 00:09

Ayaz Ali Shah


With the help of this link.. I found that these steps will activate gRPC

  1. From PECL site (or windows.php.net which has the exact same files) .. choose DLL of the latest stable release enter image description here

  2. According to the PHP version you have :

    • For XAMPP with PHP > 7.2.15 .. choose Thread Safe (TS) x64

    • For older XAMPP .. choose Thread Safe (TS) x86

  3. Download the ZIP file then extract its contents

  4. Copy the php_grpc.dll file to the extensions folder in XAMPP (you can find the path in php.ini) .. in my case it was extension_dir="C:\xampp\php\ext"
  5. Enable the extension in your php.ini file :

    • For PHP version 7.2 and up .. add extension=grpc

    • For older PHP .. add extension=php_grpc.dll

  6. Restart XAMPP and the extension will be activated as showed in phpinfo()

enter image description here

like image 197
MujtabaFR Avatar answered Sep 20 '22 00:09

MujtabaFR


Windows 10 | PHP 7.1

I tried to debug this for 4 hours and could not find the right solution. I later on realized that besides the grpc extension, there were some other extensions also like oci which threw the same error when I tried to uncomment those (while keeping grpc commented) and running any php command like php --ini

On some other forum I read that a user had to manually install PHP using windows installer and then install DLL. I thought I'll try that but I could not find an MSI so I downloaded the latest PHP zip installer from https://windows.php.net/download/ I chose the x64 version for php 7.1.

Please note that I did not install this downloaded PHP but I noticed it had a php7.dll I had used dependency walker from http://www.dependencywalker.com/ to check the dependencies of the php_grpc.dll and found php7.dll as a dependency.

So what I did was to copy both PHP7.dll and php_grpc.dll to system32 and then I tried to install that DLL. I ran a command prompt as Admin and navigated to C:\windows\system32 and executed the command regsvr32 php_grpc.dll (Please note that this does not work without PHP7.dll being present in the same folder - or at least it did not work for me). Upon execution, I got a message that the DLL was loaded but entry point was not found. At this time when I executed php --ini again (I also had php_grpc.dll loaded to ext folder under the XAMPP php folder) I got a new error finally which said that the module being loaded was Non thread safe (NTS) whereas PHP was TS (Thread Safe). So I went to PECL, downloaded the TS version of the grpc plugin for PHP7.1 and pasted the dll file to both system32 and also the ext folder. I ran the regsvr32 /U php_grpc.dll command which uninstalls and reinstalls the DLL i believe (I am not sure if this step made any difference but I am mentioning it here because I had performed this step before calling php --ini)

After this, finally php --ini ran without any issues. I was able to use the composer command to successfully download the dependencies for cloud-firestore. It was a waste of 4 precious hours but I hope this helps someone else.

NOTE: Instead of downloading from PECL, I downloaded the grpc zip from https://windows.php.net/downloads/pecl/releases/grpc/

I don't know if this is different but it was the link mentioned on the installation site for Windows installation of PHP. Also someone else has that link here. I took the latest build which was 1.24.0 at the time of this post. And I chose the Thread Safe Version.

The reason I chose the thread safe version is because of the error that I received of version mismatch. You can also check your version by executing "php -i" in console which returns same info as phpinfo(); Copy and paste the output in some text editor and search for PHP Extension Build. below is what I saw

PHP Extension Build => API20160303,TS,VC14

Note, it is TS aka thread safe. So unlike other posts on the internet where folks downloaded non thread safe version of grpc, I downloaded threadsafe and it worked.

like image 21
Soniya Ahuja Avatar answered Sep 20 '22 00:09

Soniya Ahuja