Merge pull request #9574 from stanley-cheung/php-update-gen-code-examples
PHP: update README and apache/nginx examples
diff --git a/composer.json b/composer.json
index c5c7ae8..53ae638 100644
--- a/composer.json
+++ b/composer.json
@@ -7,7 +7,7 @@
"license": "BSD-3-Clause",
"require": {
"php": ">=5.5.0",
- "google/protobuf": "v3.1.0-alpha-1"
+ "google/protobuf": "v3.1.0"
},
"require-dev": {
"google/auth": "v0.9"
diff --git a/src/php/README.md b/src/php/README.md
index 320220d..ed91d2f 100644
--- a/src/php/README.md
+++ b/src/php/README.md
@@ -12,24 +12,28 @@
* `composer`
* `phpunit` (optional)
-**Ubuntu/Debian:**
+**Install PHP and PECL on Ubuntu/Debian:**
```sh
-$ sudo apt-get install php5 php5-dev
+$ sudo apt-get install php5 php5-dev php-pear
+
+OR
+
+$ sudo apt-get install php7.0 php7.0-dev php-pear
```
-**PEAR/PECL:**
+**Install PECL on Mac:**
```sh
$ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar
```
-**Composer:**
+**Install Composer (Linux or Mac):**
```sh
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
```
-**PHPUnit:**
+**Install PHPUnit (Linux or Mac):**
```sh
$ wget https://phar.phpunit.de/phpunit-old.phar
$ chmod +x phpunit-old.phar
@@ -48,6 +52,14 @@
extension directory. You should be able to run the [unit tests](#unit-tests),
with the PHP extension installed.
+**Update php.ini**
+
+Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini`
+
+```sh
+extension=grpc.so
+```
+
**Add the gRPC PHP library as a Composer dependency**
@@ -55,7 +67,7 @@
```
"require": {
- "grpc/grpc": "v1.0.0"
+ "grpc/grpc": "v1.1.0"
}
```
@@ -96,14 +108,6 @@
$ sudo make install
```
-### Update php.ini
-
-Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini`
-
-```sh
-extension=grpc.so
-```
-
## Unit Tests
You will need the source code to run tests
@@ -138,7 +142,7 @@
### Protobuf compiler
Again if you don't have it already, you need to install the protobuf compiler
-`protoc`, version 3.1.0+.
+`protoc`, version 3.2.0+.
If `protoc` hasn't been installed, you can download the `protoc` binaries from
[the protocol buffers Github repository](https://github.com/google/protobuf/releases).
@@ -209,6 +213,7 @@
```
Add this line to your `php.ini` file, e.g. `/etc/php5/apache2/php.ini`
+or `/etc/php/7.0/apache2/php.ini`
```sh
extension=grpc.so
@@ -235,7 +240,7 @@
$ composer install
```
-Make sure you have generated the client stub `math.php`
+Make sure you have generated the client stubs
```sh
$ ./bin/generate_proto_php.sh
@@ -247,11 +252,10 @@
$ cp tests/generated_code/math_client.php /var/www/html
```
-You may have to fix the first two lines to point the includes to your installation:
+You may have to fix the first line to point the includes to your installation:
```php
include 'vendor/autoload.php';
-include 'tests/generated_code/math.php';
```
Connect to `localhost/math_client.php` in your browser, or run this from command line:
@@ -266,6 +270,10 @@
```sh
$ sudo apt-get install nginx php5-fpm
+
+OR
+
+$ sudo apt-get install nginx php7.0-fpm
```
Add this line to your `php.ini` file, e.g. `/etc/php5/fpm/php.ini`
@@ -305,7 +313,7 @@
$ composer install
```
-Make sure you have generated the client stub `math.php`
+Make sure you have generated the client stubs
```sh
$ ./bin/generate_proto_php.sh
@@ -317,11 +325,10 @@
$ cp tests/generated_code/math_client.php /var/www/html
```
-You may have to fix the first two lines to point the includes to your installation:
+You may have to fix the first line to point the includes to your installation:
```php
include 'vendor/autoload.php';
-include 'tests/generated_code/math.php';
```
Connect to `localhost/math_client.php` in your browser, or run this from command line:
diff --git a/src/php/composer.json b/src/php/composer.json
index 746474d..8528304 100644
--- a/src/php/composer.json
+++ b/src/php/composer.json
@@ -5,7 +5,7 @@
"version": "1.2.0",
"require": {
"php": ">=5.5.0",
- "google/protobuf": "v3.1.0-alpha-1"
+ "google/protobuf": "v3.1.0"
},
"require-dev": {
"google/auth": "v0.9"
diff --git a/src/php/tests/generated_code/math_client.php b/src/php/tests/generated_code/math_client.php
index 6ee92bc..9ddb1c8 100644
--- a/src/php/tests/generated_code/math_client.php
+++ b/src/php/tests/generated_code/math_client.php
@@ -32,9 +32,10 @@
*
*/
-# Fix the following two lines to point to your installation
+# Fix the following line to point to your installation
+# This assumes that you are using protoc 3.2.0+ and the generated stubs
+# were being autoloaded via composer.
include 'vendor/autoload.php';
-include 'tests/generated_code/math.php';
function p($line)
{
@@ -43,7 +44,7 @@
$host = 'localhost:50051';
p("Connecting to host: $host");
-$client = new math\MathClient($host, [
+$client = new Math\MathClient($host, [
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);
p('Client class: '.get_class($client));
@@ -52,7 +53,7 @@
p('Running unary call test:');
$dividend = 7;
$divisor = 4;
-$div_arg = new math\DivArgs();
+$div_arg = new Math\DivArgs();
$div_arg->setDividend($dividend);
$div_arg->setDivisor($divisor);
$call = $client->Div($div_arg);
@@ -65,7 +66,7 @@
p('Running server streaming test:');
$limit = 7;
-$fib_arg = new math\FibArgs();
+$fib_arg = new Math\FibArgs();
$fib_arg->setLimit($limit);
$call = $client->Fib($fib_arg);
$result_array = iterator_to_array($call->responses());
@@ -79,7 +80,7 @@
p('Running client streaming test:');
$call = $client->Sum();
for ($i = 0; $i <= $limit; ++$i) {
- $num = new math\Num();
+ $num = new Math\Num();
$num->setNum($i);
$call->write($num);
}
@@ -91,7 +92,7 @@
p('Running bidi-streaming test:');
$call = $client->DivMany();
for ($i = 0; $i < 7; ++$i) {
- $div_arg = new math\DivArgs();
+ $div_arg = new Math\DivArgs();
$dividend = 2 * $i + 1;
$divisor = 3;
$div_arg->setDividend($dividend);
diff --git a/templates/composer.json.template b/templates/composer.json.template
index accfb38..f56ecb6 100644
--- a/templates/composer.json.template
+++ b/templates/composer.json.template
@@ -9,7 +9,7 @@
"license": "BSD-3-Clause",
"require": {
"php": ">=5.5.0",
- "google/protobuf": "v3.1.0-alpha-1"
+ "google/protobuf": "v3.1.0"
},
"require-dev": {
"google/auth": "v0.9"
diff --git a/templates/src/php/composer.json.template b/templates/src/php/composer.json.template
index 08710d3..ecc516d 100644
--- a/templates/src/php/composer.json.template
+++ b/templates/src/php/composer.json.template
@@ -7,7 +7,7 @@
"version": "${settings.php_version.php_composer()}",
"require": {
"php": ">=5.5.0",
- "google/protobuf": "v3.1.0-alpha-1"
+ "google/protobuf": "v3.1.0"
},
"require-dev": {
"google/auth": "v0.9"