• Home
Name Date Size #Lines LOC

..--

README.mdD12-May-20241.6 KiB8749

apache.DockerfileD12-May-20241.3 KiB5232

base.DockerfileD12-May-20241.2 KiB4129

cli.DockerfileD12-May-20241.3 KiB5332

client.phpD12-May-20241.3 KiB4616

composer.jsonD12-May-2024176 1312

echo.protoD12-May-20243.4 KiB10181

fpm.DockerfileD12-May-20241.3 KiB5232

nginx.confD12-May-2024517 2418

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