blob: 981319a451ead0fcbde23fdd0432489648d7481f [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
Stanley Cheung46d94bb2016-05-19 16:47:52 -070020require dirname(__FILE__).'/vendor/autoload.php';
Stanley Cheungc290c112017-01-31 20:29:17 -080021
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 Cheungf8401a72015-05-29 15:09:04 -070026
Stanley Cheung46d94bb2016-05-19 16:47:52 -070027function greet($name)
28{
Stanley Cheungc290c112017-01-31 20:29:17 -080029 $client = new Helloworld\GreeterClient('localhost:50051', [
Stanley Cheung46d94bb2016-05-19 16:47:52 -070030 'credentials' => Grpc\ChannelCredentials::createInsecure(),
31 ]);
Stanley Cheungc290c112017-01-31 20:29:17 -080032 $request = new Helloworld\HelloRequest();
Stanley Cheung46d94bb2016-05-19 16:47:52 -070033 $request->setName($name);
34 list($reply, $status) = $client->SayHello($request)->wait();
35 $message = $reply->getMessage();
36
37 return $message;
Stanley Cheungf8401a72015-05-29 15:09:04 -070038}
39
40$name = !empty($argv[1]) ? $argv[1] : 'world';
Stanley Cheung46d94bb2016-05-19 16:47:52 -070041echo greet($name)."\n";