mirror of
https://github.com/php-win-ext/grpc.git
synced 2026-03-24 17:12:19 +01:00
- PHP 7.4 and 8.0 have been EOL https://www.php.net/supported-versions.php - See go/drop-php-8.0 for more details Most of the changes came from `generate_projects.sh` after updating the `tools/buildgen/plugins/expand_version.py` file. The change to `tools/internal_ci/helper_scripts/prepare_build_macos_rc` is manual. Closes #35964 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35964 from stanley-cheung:php-update-to-8_1 0c24c4eac21acae9208473363b1d3f737976ccd3 PiperOrigin-RevId: 609495798
gRPC PHP End-to-End Examples
This page shows a number of ways to create a PHP gRPC client and connect with a gRPC backend service.
Run the Server
For all the following examples, we use a simple gRPC server, written in Node.
$ git clone https://github.com/grpc/grpc-web
$ cd grpc-web
$ docker-compose build prereqs node-server
$ docker run -d -p 9090:9090 --name node-server grpcweb/node-server
Install the gRPC PECL extension
All the following commands are assumed to be run from this current directory.
$ cd grpc/examples/php/echo
In order to build a PHP gRPC client, we need to install the grpc extension
first.
$ docker build -t grpc-php/base -f ./base.Dockerfile .
CLI
Let's first build a simple CLI gRPC client:
$ docker build -t grpc-php/echo-client -f ./cli.Dockerfile .
$ docker run -it --rm --link node-server:node-server grpc-php/echo-client
$ php client.php
Apache
Now let's see how the gRPC PHP client can run with Apache:
$ docker build -t grpc-php/apache -f ./apache.Dockerfile .
$ docker run -it --rm --link node-server:node-server -p 80:80 grpc-php/apache
Open the browser to http://localhost.
Nginx + FPM
We can also try running PHP-FPM and put Nginx in front of it.
The PHP-FPM part:
$ docker build -t grpc-php/fpm -f ./fpm.Dockerfile .
$ docker run -it --rm --link node-server:node-server -p 9000:9000 \
--name fpm grpc-php/fpm
The Nginx part:
$ docker run -it --rm -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro \
--link fpm:fpm -p 80:80 nginx:1.17.4
Open the browser to http://localhost.