blob: 01c4db61aee8bd85f4f0e10272999f05e57730d2 [file] [log] [blame] [view]
Jayant Kolhe300748e2015-02-19 11:30:40 -08001
2#Overview
3
4This directory contains source code for PHP implementation of gRPC layered on shared C library.
5
6#Status
7
Stanley Cheung76ed0cc2015-06-25 15:38:59 -07008Alpha : Ready for early adopters
Jayant Kolhe300748e2015-02-19 11:30:40 -08009
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070010## Environment
mlumishb892a272014-12-09 16:28:23 -080011
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070012Prerequisite: PHP 5.5 or later, `phpunit`, `pecl`
13
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070014**Linux:**
mlumishb892a272014-12-09 16:28:23 -080015
Stanley Cheungcb14eab2015-06-16 17:33:34 -070016```sh
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070017$ sudo apt-get install php5 php5-dev phpunit php-pear
18```
19
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070020**Mac OS X:**
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070021
22```sh
23$ curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar
24$ chmod +x phpunit.phar
25$ sudo mv phpunit.phar /usr/local/bin/phpunit
26
27$ curl -O http://pear.php.net/go-pear.phar
28$ sudo php -d detect_unicode=0 go-pear.phar
Stanley Cheungcb14eab2015-06-16 17:33:34 -070029```
murgatroid99975a07b2015-02-02 14:10:42 -080030
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070031## Quick Install
mlumishb892a272014-12-09 16:28:23 -080032
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070033**Linux (Debian):**
34
Stanley Cheung5329e4b2015-08-19 15:59:59 -070035Add [Debian unstable][] to your `sources.list` file. Example:
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070036
37```sh
38echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" | \
39sudo tee -a /etc/apt/sources.list
40```
41
42Install the gRPC debian package
43
44```sh
45sudo apt-get update
46sudo apt-get install libgrpc-dev
47```
48
49Install the gRPC PHP extension
50
51```sh
52sudo pecl install grpc-alpha
53```
54
55**Mac OS X:**
56
57Install [homebrew][]. Example:
58
59```sh
60ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
61```
62
63Install the gRPC core library and the PHP extension in one step
Stanley Cheung3fa51a32015-06-09 16:16:42 -070064
65```sh
66$ curl -fsSL https://goo.gl/getgrpc | bash -s php
mlumishb892a272014-12-09 16:28:23 -080067```
68
Stanley Cheung3fa51a32015-06-09 16:16:42 -070069This will download and run the [gRPC install script][] and compile the gRPC PHP extension.
mlumishb892a272014-12-09 16:28:23 -080070
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070071
Stanley Cheung3fa51a32015-06-09 16:16:42 -070072## Build from Source
mlumishb892a272014-12-09 16:28:23 -080073
Stanley Cheung3fa51a32015-06-09 16:16:42 -070074Clone this repository
mlumishb892a272014-12-09 16:28:23 -080075
Stanley Cheung3fa51a32015-06-09 16:16:42 -070076```
77$ git clone https://github.com/grpc/grpc.git
78```
mlumishb892a272014-12-09 16:28:23 -080079
Stanley Cheung3fa51a32015-06-09 16:16:42 -070080Build and install the Protocol Buffers compiler (protoc)
81
82```
83$ cd grpc
84$ git pull --recurse-submodules && git submodule update --init --recursive
85$ cd third_party/protobuf
86$ ./autogen.sh
87$ ./configure
88$ make
89$ make check
90$ sudo make install
91```
92
Stanley Cheungcb14eab2015-06-16 17:33:34 -070093Build and install the gRPC C core libraries
Stanley Cheung3fa51a32015-06-09 16:16:42 -070094
95```sh
96$ cd grpc
97$ make
98$ sudo make install
99```
100
Stanley Cheungcb14eab2015-06-16 17:33:34 -0700101Install the gRPC PHP extension
102
103```sh
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -0700104$ sudo pecl install grpc-alpha
Stanley Cheungcb14eab2015-06-16 17:33:34 -0700105```
106
107OR
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700108
109```sh
110$ cd grpc/src/php/ext/grpc
111$ phpize
112$ ./configure
113$ make
114$ sudo make install
115```
116
Stanley Cheungf8bfd9a2015-06-25 16:11:20 -0700117In your php.ini file, add the line `extension=grpc.so` to load the extension
118at PHP startup.
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700119
120Install Composer
121
122```sh
123$ cd grpc/src/php
124$ curl -sS https://getcomposer.org/installer | php
125$ php composer.phar install
126```
127
128## Unit Tests
129
130Run unit tests
131
132```sh
133$ cd grpc/src/php
134$ ./bin/run_tests.sh
135```
136
137## Generated Code Tests
138
139Install `protoc-gen-php`
140
141```sh
142$ cd grpc/src/php/vendor/datto/protobuf-php
143$ gem install rake ronn
144$ rake pear:package version=1.0
145$ sudo pear install Protobuf-1.0.tgz
146```
147
148Generate client stub code
149
150```sh
151$ cd grpc/src/php
152$ ./bin/generate_proto_php.sh
153```
154
155Run a local server serving the math services
156
157 - Please see [Node][] on how to run an example server
158
159```sh
160$ cd grpc/src/node
161$ npm install
162$ nodejs examples/math_server.js
163```
164
165Run the generated code tests
166
167```sh
168$ cd grpc/src/php
169$ ./bin/run_gen_code_test.sh
170```
171
172[homebrew]:http://brew.sh
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700173[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
174[Node]:https://github.com/grpc/grpc/tree/master/src/node/examples
Stanley Cheung5329e4b2015-08-19 15:59:59 -0700175[Debian unstable]:https://www.debian.org/releases/sid/