Code Monkey home page Code Monkey logo

thriftdemo_php_cpp's Introduction

Thrift Demo. PHP client call CPP server

What is Thrift

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

This Demo

PHP client call CPP server.

Work Flow

  1. PHP client call with Request.
  2. CPP server response with Response.

image

Thrift interface definition

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);
}


Folders

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

How to run

Preparation

  • CMake, make, g++ ...
  • php, web server(apache or nginx, php-fpm)
  • thrift (How to install)

Compile and run

  1. cd ThriftDemo/CPP
  2. mkdir build
  3. cd build
  4. cmake ..
  5. make
  6. ./TTG.run // Run the CPP server
  7. Run ThriftDemo/PHP/client.php

thriftdemo_php_cpp's People

Contributors

zekunyan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.