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 | |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 20 | require dirname(__FILE__).'/vendor/autoload.php'; |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 21 | |
| 22 | // The following includes are needed when using protobuf 3.1.0 |
| 23 | // and will suppress warnings when using protobuf 3.2.0+ |
| 24 | @include_once dirname(__FILE__).'/helloworld.pb.php'; |
| 25 | @include_once dirname(__FILE__).'/helloworld_grpc_pb.php'; |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 26 | |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 27 | function greet($name) |
| 28 | { |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 29 | $client = new Helloworld\GreeterClient('localhost:50051', [ |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 30 | 'credentials' => Grpc\ChannelCredentials::createInsecure(), |
| 31 | ]); |
Stanley Cheung | c290c11 | 2017-01-31 20:29:17 -0800 | [diff] [blame] | 32 | $request = new Helloworld\HelloRequest(); |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 33 | $request->setName($name); |
| 34 | list($reply, $status) = $client->SayHello($request)->wait(); |
| 35 | $message = $reply->getMessage(); |
| 36 | |
| 37 | return $message; |
Stanley Cheung | f8401a7 | 2015-05-29 15:09:04 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | $name = !empty($argv[1]) ? $argv[1] : 'world'; |
Stanley Cheung | 46d94bb | 2016-05-19 16:47:52 -0700 | [diff] [blame] | 41 | echo greet($name)."\n"; |