Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
README.md | D | 12-May-2024 | 1.6 KiB | 87 | 49 | |
apache.Dockerfile | D | 12-May-2024 | 1.3 KiB | 52 | 32 | |
base.Dockerfile | D | 12-May-2024 | 1.2 KiB | 41 | 29 | |
cli.Dockerfile | D | 12-May-2024 | 1.3 KiB | 53 | 32 | |
client.php | D | 12-May-2024 | 1.3 KiB | 46 | 16 | |
composer.json | D | 12-May-2024 | 176 | 13 | 12 | |
echo.proto | D | 12-May-2024 | 3.4 KiB | 101 | 81 | |
fpm.Dockerfile | D | 12-May-2024 | 1.3 KiB | 52 | 32 | |
nginx.conf | D | 12-May-2024 | 517 | 24 | 18 |
README.md
1 2# gRPC PHP End-to-End Examples 3 4This page shows a number of ways to create a PHP gRPC client and connect with 5a gRPC backend service. 6 7 8## Run the Server 9 10For all the following examples, we use a simple gRPC server, written in Node. 11 12```sh 13$ git clone https://github.com/grpc/grpc-web 14$ cd grpc-web 15$ docker-compose build common node-server 16$ docker run -d -p 9090:9090 --name node-server grpcweb/node-server 17``` 18 19 20## Install the gRPC PECL extension 21 22All the following commands are assumed to be run from this current directory. 23 24```sh 25$ cd grpc/examples/php/echo 26``` 27 28 29In order to build a PHP gRPC client, we need to install the `grpc` extension 30first. 31 32```sh 33$ docker build -t grpc-php/base -f ./base.Dockerfile . 34``` 35 36 37## CLI 38 39 40Let's first build a simple CLI gRPC client: 41 42```sh 43$ docker build -t grpc-php/echo-client -f ./cli.Dockerfile . 44$ docker run -it --rm --link node-server:node-server grpc-php/echo-client 45$ php client.php 46``` 47 48 49 50## Apache 51 52 53Now let's see how the gRPC PHP client can run with Apache: 54 55```sh 56$ docker build -t grpc-php/apache -f ./apache.Dockerfile . 57$ docker run -it --rm --link node-server:node-server -p 80:80 grpc-php/apache 58``` 59 60Open the browser to `http://localhost`. 61 62 63 64## Nginx + FPM 65 66 67We can also try running PHP-FPM and put Nginx in front of it. 68 69 70The PHP-FPM part: 71 72```sh 73$ docker build -t grpc-php/fpm -f ./fpm.Dockerfile . 74$ docker run -it --rm --link node-server:node-server -p 9000:9000 \ 75 --name fpm grpc-php/fpm 76``` 77 78The Nginx part: 79 80```sh 81$ docker run -it --rm -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro \ 82 --link fpm:fpm -p 80:80 nginx:1.17.4 83``` 84 85 86Open the browser to `http://localhost`. 87