![]() |
|
sfThriftPlugin - 1.1.1Simple Symfony Thrift Plugin |
|
![]() |
4
users
Sign-in
to change your status |
A simple Apache Thrift plugin. Base for other Thrift plugins. |
A simple Apache Thrift plugin. Base for other Thrift plugins.
| Name | Status | |
|---|---|---|
|
|
lead | moc.liamg <<ta>> pur.zsamot |
|
|
developer | moc.liamg <<ta>> izdoluta |
The MIT License
Copyright 2010 Tomasz Jakub Rup
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Copyright 2010 Tomasz Jakub Rup
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
| Version | License | API | Released |
|---|---|---|---|
| 1.1.1stable | MIT license | 1.1.1stable | 06/09/2011 |
| 1.1.0stable | MIT license | 1.1.0stable | 13/11/2010 |
| 1.0.0stable | MIT license | 1.0.0stable | 28/10/2010 |
| 0.1.894183alpha | MIT license | 0.1.0alpha | 17/06/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.1stable | MIT license | 1.1.1stable | 06/09/2011 |
| 1.1.0stable | MIT license | 1.1.0stable | 13/11/2010 |
| 1.0.0stable | MIT license | 1.0.0stable | 28/10/2010 |
| 0.1.894183alpha | MIT license | 0.1.0alpha | 17/06/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 0.1.894183alpha | MIT license | 0.1.0alpha | 17/06/2010 |
A simple Apache Thrift plugin. Base for other Thrift plugins.
Install the plugin
$ symfony plugin:install sfThriftPlugin
Configuration is in app.yml:
all:
thrift_plugin:
default:
connector:
class: TSocket
param:
host: 127.0.0.1
port: 9090
transport:
class: TBufferedTransport
protocol:
class: TBinaryProtocol
THttpClient
HTTP client
Params:
TMemoryBuffer
A memory buffer is a tranpsort that simply reads from and writes to an in-memory string buffer. Anytime you call write on it, the data is simply placed into a buffer, and anytime you call read, data is read from that buffer.
Params:
TPhpStream
Php stream transport. Reads to and writes from the php standard streams php://input and php://output
Params:
TServerSocket
Params:
TSocket
Params:
TSocketPool
Params:
TBufferedTransport
Buffered transport. Stores data to an internal buffer that it doesn't actually write out until flush is called. For reading, we do a greedy read and then serve data out of the internal buffer.
Params:
TFramedTransport
Framed transport. Writes and reads data in chunks that are stamped with their length.
Params:
TNullTransport
Transport that only accepts writes and ignores them. This is useful for measuring the serialized size of structures.
TBinaryProtocol
Binary protocol.
Params:
TBinaryProtocolAccelerated
Accelerated binary protocol.
Params:
TCompactProtocol
Compact protocol.
Generate files
$ thrift --gen php example.thrift
Copy those generated files to your project lib directory
Remove include ... lines from generated files
Create a client object:
$service = new example_serviceClient(ThriftProtocolFactory::factory());
We can create many named configurations:
all:
thrift_plugin:
# First service configuration
service1:
connector:
class: TSocket
param:
host: 127.0.0.1
port: 9090
transport:
class: TBufferedTransport
protocol:
class: TBinaryProtocol
# Second service configuration
service2:
connector:
class: TSocket
param:
host: 192.168.1.1
port: 9091
transport:
class: TFramedTransport
protocol:
class: TBinaryProtocolAccelerated
Now we can use it:
$service1 = new FirstClient(ThriftProtocolFactory::factory('service1'));
$service2 = new SecondClient(ThriftProtocolFactory::factory('service2'));
This is example from Thrift project site:
Create UserStorage.thrift file:
struct UserProfile {
1: i32 uid,
2: string name,
3: string blurb
}
service UserStorage {
void store(1: UserProfile user),
UserProfile retrieve(1: i32 uid)
}
Generate UserStorage service files for PHP:
thrift --gen php UserStorage.thrift
Move generated files to proper place (like lib/thrift folder)
Remove include ... lines from generated files
Use client:
$service = new UserStorageClient(ThriftProtocolFactory::factory());
$service->store($user);
$user2 = $service->retrieve(1);
