blob: 08928161371b0b071e6b001c1da3b30230cfc77f [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
Stanley Cheung1894f182015-08-19 16:32:39 -070042Install the gRPC Debian package
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070043
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 Cheung7b773e92015-08-28 09:53:16 -070076```sh
Stanley Cheung3fa51a32015-06-09 16:16:42 -070077$ git clone https://github.com/grpc/grpc.git
78```
mlumishb892a272014-12-09 16:28:23 -080079
Stanley Cheungcb14eab2015-06-16 17:33:34 -070080Build and install the gRPC C core libraries
Stanley Cheung3fa51a32015-06-09 16:16:42 -070081
82```sh
83$ cd grpc
Stanley Cheung7b773e92015-08-28 09:53:16 -070084$ git pull --recurse-submodules && git submodule update --init --recursive
Stanley Cheung3fa51a32015-06-09 16:16:42 -070085$ make
86$ sudo make install
87```
88
Stanley Cheung7b773e92015-08-28 09:53:16 -070089Note: you may encounter a warning about the Protobuf compiler `protoc` 3.0.0+ not being installed. The following might help, and will be useful later on when we need to compile the `protoc-gen-php` tool.
90
91```sh
92$ cd grpc/third_party/protobuf
93$ sudo make install # 'make' should have been run by core grpc
94```
95
Stanley Cheungcb14eab2015-06-16 17:33:34 -070096Install the gRPC PHP extension
97
98```sh
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070099$ sudo pecl install grpc-alpha
Stanley Cheungcb14eab2015-06-16 17:33:34 -0700100```
101
102OR
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700103
104```sh
105$ cd grpc/src/php/ext/grpc
106$ phpize
107$ ./configure
108$ make
109$ sudo make install
110```
111
Stanley Cheungf8bfd9a2015-06-25 16:11:20 -0700112In your php.ini file, add the line `extension=grpc.so` to load the extension
113at PHP startup.
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700114
115Install Composer
116
117```sh
118$ cd grpc/src/php
119$ curl -sS https://getcomposer.org/installer | php
120$ php composer.phar install
121```
122
123## Unit Tests
124
125Run unit tests
126
127```sh
128$ cd grpc/src/php
129$ ./bin/run_tests.sh
130```
131
132## Generated Code Tests
133
134Install `protoc-gen-php`
135
136```sh
137$ cd grpc/src/php/vendor/datto/protobuf-php
138$ gem install rake ronn
139$ rake pear:package version=1.0
140$ sudo pear install Protobuf-1.0.tgz
141```
142
143Generate client stub code
144
145```sh
146$ cd grpc/src/php
147$ ./bin/generate_proto_php.sh
148```
149
150Run a local server serving the math services
151
152 - Please see [Node][] on how to run an example server
153
154```sh
155$ cd grpc/src/node
156$ npm install
157$ nodejs examples/math_server.js
158```
159
160Run the generated code tests
161
162```sh
163$ cd grpc/src/php
164$ ./bin/run_gen_code_test.sh
165```
166
167[homebrew]:http://brew.sh
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700168[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
169[Node]:https://github.com/grpc/grpc/tree/master/src/node/examples
Stanley Cheung5329e4b2015-08-19 15:59:59 -0700170[Debian unstable]:https://www.debian.org/releases/sid/