PHP code example of hyperftars / tars

1. Go to this page and download the library: Download hyperftars/tars 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/ */

    

hyperftars / tars example snippets



return [
    'obj' => [
        'home-api' => 'App\TarsRpc\obj\AccountServiceServant',
        'protocolName' => 'tars', //http, json, tars or other
        'serverType' => 'tcp', //http(no_tars default), websocket, tcp(tars default), udp
    ],
];


/**
 * Created by PhpStorm.
 * User: liangchen
 * Date: 2018/2/24
 * Time: 下午3:43.
 */

return array(
    'appName' => 'swapi',
    'serverName' => 'account',
    'objName' => 'obj',
    'withServant' => true, //决定是服务端,还是客户端的自动生成
    'tarsFiles' => array(
        './example.tars',
    ),
    'dstPath' => '../src/app/TarsRpc',
    'namespacePrefix' => 'App\TarsRpc',
);



namespace App\TarsRpc;
use Hyperf\RpcServer\Annotation\RpcService;
use App\TarsRpc\obj\AccountServiceServant;
/**
 * 路由注解
 * @RpcService(name="swapi.account.obj", protocol="tars", server="obj")
 */
class PHPServerServantImpl implements AccountServiceServant
{
    /**
     * @param string $username
     * @return bool
     */
    public function accountCheckUsername($username)
    {
        return true;
    }
}


{
  "app": "xxx", #tars应用名
  "server": "xxx", #tars服务名
  "token": "xxxxx", #tars token
  "tars_url": "http://xx.xx.xx.xx:3000", #tars web 地址
  "ignore": [
    ".gitignore",".idea/" #想要屏蔽的目录或文件
  ]
}
shell script
php bin/hyperf.php vendor:publish hyperftars/tars
shell script
cd tars
php ../src/vendor/phptars/tars2php/src/tars2php.php ./tars.proto.php