PHP code example of darkgel / thrift-manager
1. Go to this page and download the library: Download darkgel/thrift-manager 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/ */
darkgel / thrift-manager example snippets
return [
//default配置
'namespacePrefix' => '',命名空间前缀
'sendTimeout' => 3000,//毫秒
'recvTimeout' => 3000,//毫秒
'retry' => 3,
'singleServiceConnectionConfig' => [
//没有使用多路协议
'TestService'=>[
'clientClassName' => 'test\TestServiceClient',
'serverHost' => '127.0.0.1',
'serverPort' => '9292',
'sendTimeout' => 30000,
'recvTimeout' => 30000,
'retry' => 3,
],
],
'multipleServiceConnectionConfig' => [
//使用多路协议的配置例子
'localhost:7911' => [
'sendTimeout' => 20,
'recvTimeout' => 20,
'serverHost' => '10.3.20.168',
'serverPort' => 7911,
'retry' => 2,
'services' => [//这里可以配置多个服务
'MultiplicationService' => [
'clientClassName' => 'thriftgen\service\MultiplicationServiceClient',
],
'AdditionService' => [
'clientClassName' => 'thriftgen\service\AdditionServiceClient',
],
],
],
],
];
namespace App\Services\Thrift;
use Darkgel\Thrift\ThriftServiceTrait;
class ThriftService
{
use ThriftServiceTrait;
/**
* 以静态调用的方式调用thrift service的方法时,会使用到该方法
* 此处重写Trait中方法,加入自己的日志处理等功能
* @param string $name 方法名
* @param array $arguments 参数
*
* @return array 调用的返回值
*/
public static function __callStatic($name, $arguments)
{
try{
static::getInstance()->invoke($name, $arguments);
$result = static::getInstance()->getData();
// 记录日志
return $result;
} catch (\Exception $e) {
// 记录日志
// 抛出自定义异常
}
}
}