Thriftsocketserver_PHP tutorial implemented by php-php Tutorial

Source: Internet
Author: User
Tags apc php server
Thriftsocketserver implemented by php. Php-thrift-server source code is directly cloned from apache's thrift Project and hosted on github: github. the code for adding or modifying comvolcathrift is as follows: libphp' -- src | -- php-thrift-server source code.
The code is directly cloned from apache's thrift Project and hosted on github:

Http://github.com/volca/thrift

The code added or changed 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
Example
Obtain the source code of thrift and compile the thrift tool. please search

Git clone git: // github.com/volca/thrift.gitinstall PHP to extend to APC and libevent:

Pecl install apc # A libevent-devel package like pecl install libevent needs to run the php socket server first. I directly modified an independent php server from the thrift test code, see thrift/test/php/TestNonblockingServer. php, which also contains the implementation of a test business code.

Cd thrift/test/php # Use the thrift command line tool to generate the php test class library make # Start The thrift service and listen to the php TestNonblockingServer on port 9090 of the local machine. the php client code is also provided to test various data types such as int, float, string, and list.

Php TestClient. php performance test
Test results of apache + php

TestVoid () = voidtestString ("Test") = "Test" testByte (1) = 1testI32 (-1) =-1testI64 (-34359738368) =-34359738368 testDouble (-852.234234234) =-852.234234234 testStruct ({"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, 4 =>-6 }) = {0 =>-10, 1 =>-9, 2 =>-8, 3 =>-7, 4 =>-6} testSet ({-2, -1, 0, 1, 2}) = {1, 1, 1, 1} testList ({-2,-1, 0, 1, 2 }) = {-2,-1, 0, 1, 2} testEnum (ONE) = 1 testEnum (TWO) = 2 testEnum (THREE) = 3 testEnum (FIVE) = 5 testEnum (EIGHT) = 8 testTypedef (309858235082523) = 309858235082523 Total time: 41 msphp + libevent socket server test results

TestVoid () = voidtestString ("Test") = "Test" testByte (1) = 1testI32 (-1) =-1testI64 (-34359738368) =-34359738368 testDouble (-852.234234234) =-852.234234234 testStruct ({"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, 4 =>-6 }) = {0 =>-10, 1 =>-9, 2 =>-8, 3 =>-7, 4 =>-6} testSet ({-2, -1, 0, 1, 2}) = {1, 1, 1, 1} testList ({-2,-1, 0, 1, 2}) = {-2,-1, 0, 1, 2} testEnum (ONE) = 1 testEnum (TWO) = 2 testEnum (THREE) = 3 testEnum (FIVE) = 5 testEnum (EIGHT) = 8 testTypedef (309858235082523) = 309858235082523 Total time: 8 ms in this test, there is no time-consuming request, the processing logic is the same, php socket server consumes only 1/5 of apache + php.

What is thrift?
Thrift does not seem to be widely circulated and has a tendency to be replaced by other technologies. Therefore, we will refer to other articles below:

Thrift consists of a software library and a series of code generation tools developed by Facebook. The purpose is to accelerate software development and implement efficient and scalable background services. The main goal is to achieve efficient and reliable communication between different programming languages. This requires a general layer to be abstracted between different languages and then implemented by different languages. Thrift allows developers to define data types and service interfaces (defined in a neutral language file ), this file is used to generate the code required to build the RPC client and server.

Simple analysis of its mechanism, Thrift is the implementation of the C/S mode, through the code generation tool interface definition file generated on the server side and client code (can be different languages ), this provides cross-language support for servers and clients.

Thrift can be divided into transport layer and protocol layer:

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

Pipeline code is directly cloned from apache's thrift Project and hosted on github: the code for adding or modifying http://github.com/volca/thrift is 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.