Thrift is an interface definition language and binary communication protocol that is used to define and create services for numerous languages. It is used as a remote procedure call (RPC) framework and was developed at Facebook for "scalable cross-language services development". It combines a software stack with a code generation engine to build services that work efficiently to a varying degree and seamlessly between C#, C++ (on POSIX-compliant systems), Cappuccino, Cocoa, Delphi, Erlang, Go, Haskell, Java, Node.js, OCaml, Perl, PHP, Python, Ruby and Smalltalk. Although developed at Facebook, it is now an open source project in the Apache Software Foundation. The implementation was described in an April 2007 technical paper released by Facebook, now hosted on Apache. -- From Wiki Apache Thrift
PHP client call CPP server.
- PHP client call with Request.
- CPP server response with Response.
namespace cpp TTG
namespace php TTG
enum ResponseState {
StateOk = 0,
StateError = 1,
StateEmpty = 2
}
struct Request {
1: i32 studentID = 0
}
struct Response {
1: i32 studentID = 0,
2: string name,
3: list<string> infos,
4: ResponseState state
}
service TTGService {
Response getStudentInfo(1: Request request);
}
CPP // CPP server source files
--CMakeLists.txt //CMake file
--... // Other cpp source files
PHP //PHP client source files
--Gen // Generated by thrift
--Thrift // Thrift php source files
--client.php // Client source file
ThriftGen // files generated by thrift
--gen-cpp
--gen-php
--TTG.thrift // definition file
- CMake, make, g++ ...
- php, web server(apache or nginx, php-fpm)
- thrift (How to install)
- cd ThriftDemo/CPP
- mkdir build
- cd build
- cmake ..
- make
- ./TTG.run // Run the CPP server
- Run ThriftDemo/PHP/client.php