Thrift PHP Client Writing

Source: Internet
Author: User

Reprint Address: http://blog.csdn.net/hshxf/article/details/5666145


1, Prepare thrift PHP Client base class, this can be obtained from the thrift source package, under THRIFTSRC/LIB/PHP/SRC, generally have the following directories and files: Ext,protocol,transport directory and thrift.php, autoload.php files, we copy these files and directories to a specified thrift root directory, such as C:/php/thrift/root

2, if it is a Linux environment, you can consider using Thrift protocol PHP Extension, compiling method: First of all mentioned in the Ext directory under the Thrift_protocol directory copy to your PHP source under the Ext directory, pay attention to modify permissions , you can directly modify to 777 permissions, and then start to enter into the Thrift_protocol directory to start compiling, in turn, execute the following command: Phpize,./configure--enable-thrift_protocol,make, Then moudles/thrift_protocol.so copy to your PHP installation directory in the ETC directory, such as PHP5/ETC, and then configure the php.ini file, restart Apache

3, using thrift--gen PHP xxx.thrift Compile the interface file, and then copy the interface file to thrift root under the packages directory, such as C:/php/thrift/root/packages

4, write client code, referring to the thiftsrc//tutorial/php under the phpclient.php, must pay attention to the first few lines of the global variable settings

$GLOBALS [' thrift_root '] = '. /.. /lib/php/src ';

require_once $GLOBALS [' thrift_root ']. ' /thrift.php ';
require_once $GLOBALS [' thrift_root ']. ' /protocol/tbinaryprotocol.php ';
require_once $GLOBALS [' thrift_root ']. ' /transport/tsocket.php ';
require_once $GLOBALS [' thrift_root ']. ' /transport/thttpclient.php ';
require_once $GLOBALS [' thrift_root ']. ' /transport/tbufferedtransport.php ';

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.