Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 1 | <?php |
| 2 | /* |
| 3 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 4 | * Copyright 2015 gRPC authors. |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 5 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 9 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 11 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
ZhouyihaiDing | 5253720 | 2017-11-05 18:25:54 -0800 | [diff] [blame^] | 20 | // php:generate protoc --proto_path=./../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../bins/opt/grpc_php_plugin ./../protos/helloworld.proto |
| 21 | |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 22 | require dirname(__FILE__).'/vendor/autoload.php'; |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 23 | |
ZhouyihaiDing | 5253720 | 2017-11-05 18:25:54 -0800 | [diff] [blame^] | 24 | @include_once dirname(__FILE__).'/Helloworld/GreeterClient.php'; |
| 25 | @include_once dirname(__FILE__).'/Helloworld/HelloReply.php'; |
| 26 | @include_once dirname(__FILE__).'/Helloworld/HelloRequest.php'; |
| 27 | @include_once dirname(__FILE__).'/GPBMetadata/Helloworld.php'; |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 28 | |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 29 | function greet($name) |
| 30 | { |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 31 | $client = new Helloworld\GreeterClient('localhost:50051', [ |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 32 | 'credentials' => Grpc\ChannelCredentials::createInsecure(), |
| 33 | ]); |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 34 | $request = new Helloworld\HelloRequest(); |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 35 | $request->setName($name); |
| 36 | list($reply, $status) = $client->SayHello($request)->wait(); |
| 37 | $message = $reply->getMessage(); |
| 38 | |
| 39 | return $message; |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | $name = !empty($argv[1]) ? $argv[1] : 'world'; |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 43 | echo greet($name)."\n"; |