PHP code example of yandy / laravel-grpc

1. Go to this page and download the library: Download yandy/laravel-grpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yandy / laravel-grpc example snippets


    namespace App\RpcClient;
    
    use App\Grpc\HiReply;
    use App\Grpc\HiUser;
    
    class UserClient extends \Grpc\BaseStub{
    
        public function __construct($hostname, $opts, $channel = null) {
            parent::__construct($hostname, $opts, $channel);
        }
    
        //测试grpc客户端
        public function sayHello(HiUser $argument,$metadata=[],$options=[]){
            return $this->_simpleRequest('/grpc.hi/sayHello',
                $argument,
                ['\App\Grpc\HiReply', 'decode'],
                $metadata, $options);
        }
    
    }
    

	      use Yandy\grpc\Facades\GrpcClient;
	      $client = GrpcClient::make('userfff');
        $request = new HiUser();
        $request->setName('wangyan');
        $request->setSex(30);
        list($reply, $status) = $client->sayHello($request)->wait();

        $message = $reply->getMessage();
        $user = $reply->getUser();
        $client->close();