sean-ren/thrift

让Thrift使用起来更简洁

dev-master 2015-12-14 02:18 UTC

This package is auto-updated.

Last update: 2024-12-19 19:40:43 UTC


README

Thrift Client Api for PHP

整合Thrift官方提供的包,融合workerman客户端连接并对其进行优化。

包加载说明

修改composer.json

"require": {
	"sean-ren/thrift"	: "0.9.*"
}

根据Thrift idl生成客户端代码,生成命令示例:

thrift --gen php message.thrift

然后加载客户端代码,可以通过composer加载;修改composer.json:

"autoload" : {
		"classmap" : ["客户端代码目录"]
}

如果对composer自动加在不熟悉可以参考composer手册

使用示例

use Thrift\Clients\ThriftClient,
	 example\Message;
ThriftClient::config(array(
                        'MessageService' => array(
                            'addresses' => array(
                               '127.0.0.1:9001'
                            ),
                            'thrift_protocol' => 'TCompactProtocol',//不配置默认是TBinaryProtocol,对应服务端Message.conf配置中的thrift_protocol
                            'thrift_transport' => 'TFramedTransport',//不配置默认是TBufferedTransport,对应服务端Message.conf配置中的thrift_transport
                            "namespace_name" => "\\example\\MessageServiceClient",
                            "service_dir" => "yourpath/example" //如果不想使用命名空间可以填写路径自动加载
                        ),
                    )
                );
$client = ThriftClient::instance("MessageService");