php: update readme

pull/5632/head
Stanley Cheung 9 years ago
parent 9b9c40cfe8
commit a41a6775d4
  1. 10
      examples/php/README.md
  2. 115
      src/php/README.md

@ -4,16 +4,15 @@ gRPC in 3 minutes (PHP)
PREREQUISITES PREREQUISITES
------------- -------------
This requires PHP 5.5 or greater. This requires `php` >=5.5, `phpize`, `pecl`, `phpunit`
INSTALL INSTALL
------- -------
- On Mac OS X, install [homebrew][]. Run the following command to install gRPC. - Install the gRPC PHP extension
```sh ```sh
$ curl -fsSL https://goo.gl/getgrpc | bash -s php $ [sudo] pecl install grpc-beta
``` ```
This will download and run the [gRPC install script][] and compile the gRPC PHP extension.
- Clone this repository - Clone this repository
@ -37,6 +36,7 @@ TRY IT!
Please follow the instruction in [Node][] to run the server Please follow the instruction in [Node][] to run the server
``` ```
$ cd examples/node $ cd examples/node
$ npm install
$ nodejs greeter_server.js $ nodejs greeter_server.js
``` ```
@ -58,7 +58,5 @@ TUTORIAL
You can find a more detailed tutorial in [gRPC Basics: PHP][] You can find a more detailed tutorial in [gRPC Basics: PHP][]
[homebrew]:http://brew.sh
[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
[Node]:https://github.com/grpc/grpc/tree/master/examples/node [Node]:https://github.com/grpc/grpc/tree/master/examples/node
[gRPC Basics: PHP]:http://www.grpc.io/docs/tutorials/basic/php.html [gRPC Basics: PHP]:http://www.grpc.io/docs/tutorials/basic/php.html

@ -9,14 +9,21 @@ Beta
## Environment ## Environment
Prerequisite: PHP 5.5 or later, `phpunit`, `pecl` Prerequisite: `php` >=5.5, `phpize`, `pecl`, `phpunit`
**Linux:** **Linux (Debian):**
```sh ```sh
$ sudo apt-get install php5 php5-dev php-pear $ sudo apt-get install php5 php5-dev php-pear
``` ```
**Linux (CentOS):**
```sh
$ yum install php55w
$ yum --enablerepo=remi,remi-php55 install php-devel php-pear
```
**Mac OS X:** **Mac OS X:**
```sh ```sh
@ -24,11 +31,11 @@ $ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar $ sudo php -d detect_unicode=0 go-pear.phar
``` ```
**PHPUnit: (Both Linux and Mac OS X)** **PHPUnit:**
```sh ```sh
$ curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar $ wget https://phar.phpunit.de/phpunit-old.phar
$ chmod +x phpunit.phar $ chmod +x phpunit-old.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit $ sudo mv phpunit-old.phar /usr/bin/phpunit
``` ```
## Quick Install ## Quick Install
@ -39,15 +46,22 @@ Install the gRPC PHP extension
sudo pecl install grpc-beta sudo pecl install grpc-beta
``` ```
This will compile and install the gRPC PHP extension into the standard PHP extension directory. You should be able to run the [unit tests](#unit-tests), with the PHP extension installed.
To run tests with generated stub code from `.proto` files, you will need the `composer`, `protoc` and `protoc-gen-php` binaries additionally. See sections [below](#generated-code-tests).
## Build from Source ## Build from Source
### gRPC C core library
Clone this repository Clone this repository
```sh ```sh
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
Build and install the gRPC C core libraries Build and install the gRPC C core library
```sh ```sh
$ cd grpc $ cd grpc
@ -56,20 +70,15 @@ $ make
$ sudo make install $ sudo make install
``` ```
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. ### gRPC PHP extension
```sh Install the gRPC PHP extension from PECL
$ cd grpc/third_party/protobuf
$ sudo make install # 'make' should have been run by core grpc
```
Install the gRPC PHP extension
```sh ```sh
$ sudo pecl install grpc-beta $ sudo pecl install grpc-beta
``` ```
OR Or, compile from source
```sh ```sh
$ cd grpc/src/php/ext/grpc $ cd grpc/src/php/ext/grpc
@ -79,58 +88,96 @@ $ make
$ sudo make install $ sudo make install
``` ```
### Update php.ini
Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini` Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini`
```sh ```sh
extension=grpc.so extension=grpc.so
``` ```
Install Composer ## Unit Tests
You will need the source code to run tests
```sh
$ git clone https://github.com/grpc/grpc.git
$ cd grpc
$ git pull --recurse-submodules && git submodule update --init --recursive
```
Run unit tests
```sh ```sh
$ cd grpc/src/php $ cd grpc/src/php
$ ./bin/run_tests.sh
```
## Generated Code Tests
### Composer
You need to install `composer`, to pull in some runtime dependencies based on the `composer.json` file.
```sh
$ curl -sS https://getcomposer.org/installer | php $ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer $ sudo mv composer.phar /usr/local/bin/composer
$ cd grpc/src/php
$ composer install $ composer install
``` ```
## Unit Tests ### Protobuf compiler
Run unit tests You need the install the protobuf compiler, `protoc`, 3.0.0+.
If you had compiled the gRPC C core library from source above, the `protoc` binary should have been installed as well. In the case it wasn't, you can run the following commands to install it.
```sh ```sh
$ cd grpc/src/php $ cd grpc/third_party/protobuf
$ ./bin/run_tests.sh $ sudo make install # 'make' should have been run by core grpc
``` ```
## Generated Code Tests Or you can download a `protoc` binaries from [here](https://github.com/google/protobuf/releases).
Install `protoc-gen-php` ### PHP protobuf compiler
You need to install `protoc-gen-php`, so that you can generate stub classes `.php` files from service definition `.proto` files.
```sh ```sh
$ cd grpc/src/php/vendor/datto/protobuf-php $ cd grpc/src/php/vendor/datto/protobuf-php # if you had run `composer install` in the previous step
OR
$ git clone https://github.com/stanley-cheung/Protobuf-PHP # clone from github repo
$ gem install rake ronn $ gem install rake ronn
$ rake pear:package version=1.0 $ rake pear:package version=1.0
$ sudo pear install Protobuf-1.0.tgz $ sudo pear install Protobuf-1.0.tgz
``` ```
Generate client stub code ### Client Stub
Generate client stub classes from `.proto` files
```sh ```sh
$ cd grpc/src/php $ cd grpc/src/php
$ ./bin/generate_proto_php.sh $ ./bin/generate_proto_php.sh
``` ```
Run a local server serving the math services ### Run test server
- Please see [Node][] on how to run an example server Run a local server serving the math services. Please see [Node][] on how to run an example server
```sh ```sh
$ cd grpc/src/node $ cd grpc
$ npm install $ npm install
$ nodejs examples/math_server.js $ nodejs src/node/test/math/math_server.js
``` ```
### Run test client
Run the generated code tests Run the generated code tests
```sh ```sh
@ -161,13 +208,15 @@ $ sudo service apache2 restart
Make sure the Node math server is still running, as above. Make sure the Node math server is still running, as above.
```sh ```sh
$ cd grpc/src/node $ cd grpc
$ nodejs examples/math_server.js $ npm install
$ nodejs src/node/test/math/math_server.js
``` ```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file Make sure you have run `composer install` to generate the `vendor/autoload.php` file
```sh ```sh
$ cd grpc/src/php
$ composer install $ composer install
``` ```
@ -229,13 +278,15 @@ $ sudo service php5-fpm restart
Make sure the Node math server is still running, as above. Make sure the Node math server is still running, as above.
```sh ```sh
$ cd grpc/src/node $ cd grpc
$ nodejs examples/math_server.js $ npm install
$ nodejs src/node/test/math/math_server.js
``` ```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file Make sure you have run `composer install` to generate the `vendor/autoload.php` file
```sh ```sh
$ cd grpc/src/php
$ composer install $ composer install
``` ```

Loading…
Cancel
Save