PHP code example of riven / hyperf-grpc-sdk

1. Go to this page and download the library: Download riven/hyperf-grpc-sdk 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/ */

    

riven / hyperf-grpc-sdk example snippets


//build.php


declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
$path = __DIR__ . '/vendor/riven/hyperf-grpc-sdk';
if (is_dir($path)) {
    shell_exec("php {$path}/build.php");
}


    /**
     * @return string
     * @throws \Exception
     */
    public function hello()
    {
        $client = new \Proto\Example\UserGrpcClient();
        $user = new \Proto\Example\HiUser();
        $user->setName('小明');
        $user->setSex(1);
        $reply = $client->sayHello($user);
        return $reply->serializeToJsonString();

    }
json
 "scripts": {
    ......
    "pre-autoload-dump": [
      "php build.php"              
    ]
  },
 "extra": {
    "scripts-dev": {
      "post-autoload-dump": [
        ......
        "php bin/hyperf.php vendor:publish riven/hyperf-grpc-sdk -f"
      ]
    }
  }