PHP implementation of the thrift Socket server_php Tutorial

Source: Internet
Author: User
Tags apc
Php-thrift-server Source
The code comes directly from the Apache Thrift Project clone, hosted on GitHub:

Http://github.com/volca/thrift

The new or changed code is as follows:

lib/php/
'--src
|--Server
| |--tnonblockingserver.php
| '--tserver.php
'--transport
|--tnonblockingserversocket.php
|--tnonblockingsocket.php
|--tserversocket.php
|--tservertransport.php
test/php
|--testclient.php
|--testnonblockingserver.php
Using the example
Get the source code of thrift and compile the Thrift tool, please search for the compilation process

git clone git://github.com/volca/thrift.git installs PHP, as well as APC, libevent extensions:

PECL install apc# need to libevent-devel such a package pecl install libevent run PHP socket server, I directly from the thrift test code to modify a separate running PHP server, See thrift/test/php/testnonblockingserver.php, which also contains an implementation of the Test business code.

CD thrift/test/php# using thrift command line tool to generate PHP test class library make# start thrift Service, will listen to the native 9090 port PHP The code for the testnonblockingserver.php client is also provided, testing for various data types such as int, float, string, list, and so on.

PHP testclient.php Performance Test
Test results for Apache + PHP

Testvoid () = voidteststring ("test") = "Test" testbyte (1) = 1TESTI32 ( -1) = -1testi64 (-34359738368) =- 34359738368testDouble ( -852.234234234) = -852.234234234teststruct ({"Zero", 1, -3,-5}) = {"Zero", 1, -3, -5}testnest ({1, { "Zero", 1, -3,-5}), 5} = {1, {"Zero", 1, -3,-5}, 5}testmap ({0 = -10, 1 +-9, 2 = 8, 3 = 7) ) = {0 = -10, 1 = 9, 2 = 8, 3 =-7, 4 = -6}testset ({-2,-1, 0, 1, 2}) = {1, 1, 1, 1, 1}testlist ({-2, -1, 0, 1, 2}) = {-2,-1, 0, 1, 2}testenum (one) = 1testEnum (double) = 2testEnum (three) = 3testEnum (FIVE) = 5testEnum (EIGHT) = 8testTypedef (309858235082523) = 309858235082523Total time:41 msphp + libevent socket Server test Results

Testvoid () = voidteststring ("test") = "Test" testbyte (1) = 1TESTI32 ( -1) = -1testi64 (-34359738368) =- 34359738368testDouble ( -852.234234234) = -852.234234234teststruct ({"Zero", 1, -3,-5}) = {"Zero", 1, -3, -5}testnest ({1, { "Zero", 1, -3,-5}), 5} = {1, {"Zero", 1, -3,-5}, 5}testmap ({0 = -10, 1 +-9, 2 = 8, 3 = 7) ) = {0 = -10, 1 = 9, 2 = 8, 3 =-7, 4 = -6}testset ({-2,-1, 0, 1, 2}) = {1, 1, 1, 1, 1}testlist ({-2, -1, 0, 1, 2}) = {-2,-1, 0, 1, 2}testenum (one) = 1testEnum (double) = 2testEnum (three) = 3testEnum (FIVE) = 5testEnum (EIGHT) = 8testTypedef (309858235082523) = 309858235082523Total Time:8 ms in this test, there is no lengthy request, the processing logic is exactly the same, the PHP socket server time is only Apache + PHP one-fifth.

What is thrift?
Thrift does not seem to be widely circulated, and there is a tendency to be replaced by other technologies, so here's a quote from another article:

Thrift consists of a software library and a series of code generation tools, developed by Facebook. The goal is to accelerate software development and enable efficient and scalable back-office services. The main goal is to achieve efficient and reliable communication between different programming languages, which requires the abstraction of a common layer between different languages and then the implementation of this universal layer by different languages. In particular, thrift allows developers to define data types and service interfaces (defined in a neutral language file) and generate the code needed to build the RPC client and server from this file.

Simple analysis of its mechanism, thrift is the implementation of the C/S mode, through the code generation tool to generate the interface definition file server-side and client code (can be different languages), in order to achieve the service side and client cross-language support.

Thrift can be divided into Transport Layer and protocol layer:

The transport layer defines the transmission mode of the data, which can be used for TCP/IP transmission, memory sharing or file sharing.
The protocol layer defines the transmission format of the data, which can be in the form of a binary stream or XML.
When the server side uses the socket protocol, it can be run in simple|thread-pool|threaded|nonblocking and other ways for better performance.

http://www.bkjia.com/PHPjc/478823.html www.bkjia.com true http://www.bkjia.com/PHPjc/478823.html techarticle Php-thrift-server source code directly from the Apache Thrift Project clone, hosted on GitHub: Http://github.com/volca/thrift Add or change the code as follows: lib/php /'--src |--...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.