File: README.md

package info (click to toggle)
grpc 1.51.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,328 kB
  • sloc: cpp: 361,873; python: 72,206; ansic: 37,787; objc: 12,434; ruby: 11,521; sh: 7,652; php: 7,615; makefile: 3,481; xml: 3,246; cs: 1,836; javascript: 1,614; java: 465; pascal: 227; awk: 132
file content (86 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

# 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.

```sh
$ 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.

```sh
$ cd grpc/examples/php/echo
```


In order to build a PHP gRPC client, we need to install the `grpc` extension
first.

```sh
$ docker build -t grpc-php/base -f ./base.Dockerfile .
```


## CLI


Let's first build a simple CLI gRPC client:

```sh
$ 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:

```sh
$ 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:

```sh
$ 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:

```sh
$ 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`.