Jayant Kolhe | 300748e | 2015-02-19 11:30:40 -0800 | [diff] [blame] | 1 | |
| 2 | #Overview |
| 3 | |
| 4 | This directory contains source code for PHP implementation of gRPC layered on shared C library. |
| 5 | |
| 6 | #Status |
| 7 | |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 8 | Alpha : Ready for early adopters |
Jayant Kolhe | 300748e | 2015-02-19 11:30:40 -0800 | [diff] [blame] | 9 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 10 | ## Environment |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 11 | |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 12 | Prerequisite: PHP 5.5 or later, `phpunit`, `pecl` |
| 13 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 14 | **Linux:** |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 15 | |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 16 | ```sh |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 17 | $ sudo apt-get install php5 php5-dev phpunit php-pear |
| 18 | ``` |
| 19 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 20 | **Mac OS X:** |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 21 | |
| 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 Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 29 | ``` |
murgatroid99 | 975a07b | 2015-02-02 14:10:42 -0800 | [diff] [blame] | 30 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 31 | ## Quick Install |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 32 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 33 | **Linux (Debian):** |
| 34 | |
Stanley Cheung | 5329e4b | 2015-08-19 15:59:59 -0700 | [diff] [blame] | 35 | Add [Debian unstable][] to your `sources.list` file. Example: |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 36 | |
| 37 | ```sh |
| 38 | echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" | \ |
| 39 | sudo tee -a /etc/apt/sources.list |
| 40 | ``` |
| 41 | |
Stanley Cheung | 1894f18 | 2015-08-19 16:32:39 -0700 | [diff] [blame] | 42 | Install the gRPC Debian package |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 43 | |
| 44 | ```sh |
| 45 | sudo apt-get update |
| 46 | sudo apt-get install libgrpc-dev |
| 47 | ``` |
| 48 | |
| 49 | Install the gRPC PHP extension |
| 50 | |
| 51 | ```sh |
| 52 | sudo pecl install grpc-alpha |
| 53 | ``` |
| 54 | |
| 55 | **Mac OS X:** |
| 56 | |
| 57 | Install [homebrew][]. Example: |
| 58 | |
| 59 | ```sh |
| 60 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 61 | ``` |
| 62 | |
| 63 | Install the gRPC core library and the PHP extension in one step |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 64 | |
| 65 | ```sh |
| 66 | $ curl -fsSL https://goo.gl/getgrpc | bash -s php |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 67 | ``` |
| 68 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 69 | This will download and run the [gRPC install script][] and compile the gRPC PHP extension. |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 70 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 71 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 72 | ## Build from Source |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 73 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 74 | Clone this repository |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 75 | |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame^] | 76 | ```sh |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 77 | $ git clone https://github.com/grpc/grpc.git |
| 78 | ``` |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 79 | |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 80 | Build and install the gRPC C core libraries |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 81 | |
| 82 | ```sh |
| 83 | $ cd grpc |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame^] | 84 | $ git pull --recurse-submodules && git submodule update --init --recursive |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 85 | $ make |
| 86 | $ sudo make install |
| 87 | ``` |
| 88 | |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame^] | 89 | Note: 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 Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 96 | Install the gRPC PHP extension |
| 97 | |
| 98 | ```sh |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 99 | $ sudo pecl install grpc-alpha |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 100 | ``` |
| 101 | |
| 102 | OR |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 103 | |
| 104 | ```sh |
| 105 | $ cd grpc/src/php/ext/grpc |
| 106 | $ phpize |
| 107 | $ ./configure |
| 108 | $ make |
| 109 | $ sudo make install |
| 110 | ``` |
| 111 | |
Stanley Cheung | f8bfd9a | 2015-06-25 16:11:20 -0700 | [diff] [blame] | 112 | In your php.ini file, add the line `extension=grpc.so` to load the extension |
| 113 | at PHP startup. |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 114 | |
| 115 | Install 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 | |
| 125 | Run unit tests |
| 126 | |
| 127 | ```sh |
| 128 | $ cd grpc/src/php |
| 129 | $ ./bin/run_tests.sh |
| 130 | ``` |
| 131 | |
| 132 | ## Generated Code Tests |
| 133 | |
| 134 | Install `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 | |
| 143 | Generate client stub code |
| 144 | |
| 145 | ```sh |
| 146 | $ cd grpc/src/php |
| 147 | $ ./bin/generate_proto_php.sh |
| 148 | ``` |
| 149 | |
| 150 | Run 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 | |
| 160 | Run 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 Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 168 | [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 Cheung | 5329e4b | 2015-08-19 15:59:59 -0700 | [diff] [blame] | 170 | [Debian unstable]:https://www.debian.org/releases/sid/ |