blob: bb94a0852787ea9379dd35bea89f6c458440cfc2 [file] [log] [blame]
Stanley Cheungf8401a72015-05-29 15:09:04 -07001<?php
2/*
3 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004 * Copyright 2015 gRPC authors.
Stanley Cheungf8401a72015-05-29 15:09:04 -07005 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02006 * 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 Cheungf8401a72015-05-29 15:09:04 -07009 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010 * http://www.apache.org/licenses/LICENSE-2.0
Stanley Cheungf8401a72015-05-29 15:09:04 -070011 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020012 * 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 Cheungf8401a72015-05-29 15:09:04 -070017 *
18 */
19
ZhouyihaiDing52537202017-11-05 18:25:54 -080020// php:generate protoc --proto_path=./../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../bins/opt/grpc_php_plugin ./../protos/helloworld.proto
21
Stanley Cheung46d94bb2016-05-19 16:47:52 -070022require dirname(__FILE__).'/vendor/autoload.php';
Stanley Cheungc290c112017-01-31 20:29:17 -080023
ZhouyihaiDing52537202017-11-05 18:25:54 -080024@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 Cheungf8401a72015-05-29 15:09:04 -070028
Stanley Cheung46d94bb2016-05-19 16:47:52 -070029function greet($name)
30{
Stanley Cheungc290c112017-01-31 20:29:17 -080031 $client = new Helloworld\GreeterClient('localhost:50051', [
Stanley Cheung46d94bb2016-05-19 16:47:52 -070032 'credentials' => Grpc\ChannelCredentials::createInsecure(),
33 ]);
Stanley Cheungc290c112017-01-31 20:29:17 -080034 $request = new Helloworld\HelloRequest();
Stanley Cheung46d94bb2016-05-19 16:47:52 -070035 $request->setName($name);
36 list($reply, $status) = $client->SayHello($request)->wait();
37 $message = $reply->getMessage();
38
39 return $message;
Stanley Cheungf8401a72015-05-29 15:09:04 -070040}
41
42$name = !empty($argv[1]) ? $argv[1] : 'world';
Stanley Cheung46d94bb2016-05-19 16:47:52 -070043echo greet($name)."\n";