

1. Document reading Quick start | PHP | gRPC Quick start | Node | gRPC grpc/README.md at v1.46.3 · grpc/grpc · GitHub https://cloud.google.com/php/grpc?hl=zh_cn#macos Releases · protocolbuffers/protobuf · GitHub https://github.com/grpc/grpc-php PHP Install and use GRPC Full tutorial - lmcc- Old horse eats grass blog https://developers.google.com/protocol-buffers/docs/reference/php-generated#invocation GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format https://pecl.php.net/package/gRPC
2. Organize output 20220606 Monday Chengdu Company This afternoon, , I learned and practiced ,gRPC Of Demo Recall process : php + nodeJS https://github.com/grpc/grpc/blob/v1.46.3/src/php/README.md https://grpc.io/docs/languages/php/quickstart/ https://grpc.io/docs/languages/node/quickstart/ Preface Like according to your habits , Select a directory as the project , The following is my working directory * php-projects pwd /Users/kumu/Documents/code/php-projects * php-projects
All scripts execute , Naturally, it should be carried out under a certain word directory under the above directory . 1. php Environmental preparation 1.1 install gprc,protobuf An extension of sudo pecl install grpc protobuf to update php.ini, pecl Installation completed , It will automatically add gprc Screenshot of expansion installation 
protobuf Screenshot of expansion installation 
You can see that the extension is automatically added to php.ini In profile , First line 
Check whether the extension is effective 
Just two lines of command php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"
Mac or Linux System :--- Global installation Open the command line window and execute the following command to download the composer.phar File move to /usr/local/bin/ Below directory : Copy sudo mv composer.phar /usr/local/bin/composer


1.3 install protoc compiler Download the binary package directly , decompression , The binary executable , Add to system environment variables https://github.com/protocolbuffers/protobuf/releases https://github.com/protocolbuffers/protobuf/releases/download/v21.1/protoc-21.1-osx-aarch_64.zip --- mac m1 View the unzipped directory structure 
Add to environment variables 
Check whether the installation is successful 
1.4 install grpc_php_plugin protoc plug-in unit Use here cmake Tools for installation , But it needs to be installed first cmake brew install cmake clone grpc project , And install protoc and grpc_php_plugin plug-in unit $ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc $ cd grpc $ git submodule update --init $ mkdir -p cmake/build $ cd cmake/build $ cmake ../.. $ make protoc grpc_php_plugin 
 perhaps -- It seems that the government also recommends this way , From the frame examples Of shell The script is visible Alternatively, you can also build the grpc_php_plugin with bazel: $ bazel build @com_google_protobuf//:protoc $ bazel build src/compiler:grpc_php_plugin
The final directory structure 
2. node Environmental preparation 2.1 install nodeJSbrew install node
3. Respectively into the client and server Language examples Next , Installation dependency cd examples/php composer install cd examples/node npm install
4. Start server here nodeJS Acted by , And you must start the server first , otherwise , Start the client first, and an error will appear , Everyone knows why ~ cd examples/node/dynamic_codegen
Run the server node greeter_server.js

Run the client from another terminal node greeter_client.js

there shell Script , In essence, it is also execution node greeter_client.js 
5. Start client from examples/php Directory , function PHP client : $ ./run_greeter_client.sh

It's essentially execution greeter_client.php Script , Here we need to put the file php cli in extension=grpc.so Get rid of , Otherwise it will be reported Warning, Load repeatedly -- In fact, it's also demo Stage ,warning It has nothing to do with elegance . in addition ,ERROR, Because the client is started first . * grpc git:(53d69cc) * ./examples/php/run_greeter_client.sh PHP Warning: Module "grpc" is already loaded in Unknown on line 0 Warning: Module "grpc" is already loaded in Unknown on line 0 ERROR: 14, failed to connect to all addresses * grpc git:(53d69cc) *
thus , The simplest rpc Call complete ~ Subsequent complement ... |