overblog/thrift-bundle
Composer 安装命令:
composer require overblog/thrift-bundle
包简介
OverBlog Thrift Bundle
README 文档
README
What is this repository ?
This is a custom version of the Thrift protocol for PHP
Usefull links ?
https://github.com/yuxel/thrift-examples
http://svn.apache.org/repos/asf/thrift/trunk/
Getting the bundle
The Composer way
Update your composer json with this new dependency into the "require" section.
// composer.json "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", ... "overblog/thrift-bundle": "*" // insert this line }
And then run composer update
Setting up the bundle
Let's start by registering the bundle into the AppKernel
// app/AppKernel.php public function registerBundles() { $bundles = array( ... new Overblog\ThriftBundle\OverblogThriftBundle(), ... ); return $bundles; }
You can now create your Service.thrift file and place it in a ThriftDefinition directory, in your own bundle.
For example: MyNameSpace/MyBundle/ThriftDefinition/Service.thrift
You need to configure the compiler to build the right files.
#app/config/config.yml overblog_thrift: services: *service_name*: definition: Service namespace: ThriftModel\Service definitionPath: /PATH/ # Path of the definition server: true # Define if server class will be generated
You are now able to generate the model with php app/console thrift:compile CompleteBundleName Service
Model will be automatically generated on the cache warmup (php app/console cache:warmup) in your cache directory.
You can set in the option "protocol" too
To use server
Create your handler that extends Overblog\ThriftBundle\Api\Extensions\BaseExtension and implements ThriftModel\Service\ServiceIf.
Then register it in your bundle:
#Bundle/Ressources/config/services.yml services: thrift.handler.service: class: BundleName\Handler\Service arguments: [@service_container]
Add the server config to your project's config.yml:
#app/config/config.yml overblog_thrift: servers: *service_name*: service: *service_name* handler: thrift_api.processor.service
If you wan't to use Thrift over HTTP Transport, you must add the bundle's routing to your project.
#app/config/routing.yml OverblogThriftBundle: resource: "@OverblogThriftBundle/Resources/config/routing.yml" prefix: /
Or you can start the socket version with the command:
php app/console thrift:server *service_name*
To use client
HTTP Client: Add this to your projects's config.yml :
#app/config/config.yml overblog_thrift: clients: *client_name*: service: *service_name*: type: http hosts: comment: host: domain/thrift port: 80
Socket Client: Add this to your projects's config.yml :
#app/config/config.yml overblog_thrift: clients: *client_name*: service: *service_name*: type: socket hosts: *host_name*: host: localhost port: 9090
Multi Socket Client: Add this to your projects's config.yml :
#app/config/config.yml overblog_thrift: clients: *client_name*: service: *service_name*: type: socket hosts: *host_name*: host: localhost port: 9090 *host_name_2*: host: localhost port: 9091
Then you can call the client:
// your_controller.php $service = $this->getContainer()->get('thrift.client.*client_name*'); $client = $service->getClient(); $service = $service->getFactory('ThriftModel\Service\Service'); $service->property = 121354984651354647; $service->name = 'Name 1'; $id = $client->execMethod($service);
Contribute
Tests:
Install phpunit.
In the bundle directory:
phpunit
overblog/thrift-bundle 适用场景与选型建议
overblog/thrift-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.54k 次下载、GitHub Stars 达 44, 最近一次更新时间为 2012 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 overblog/thrift-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 overblog/thrift-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-10-03