On May 19th, at the 6th China PHP Developers Conference (PHPCon) held in Shanghai, Tencent’s open source project TARS fully released PHP version for the first time. Liang Chen (Ted), senior development engineer of China Text Group, shared experience on how PHP builds high-performance RPC framework through TARS.

“At the very least, the existing PHP development ecosystem needs to be fully functional, flexible, lightweight and efficient.” Liang Chen said. He introduced the basic design idea of TARS, and shared the design and implementation of TARS solution at the level of PHP language and framework through the aspects of client, binary protocol, server and development efficiency.



On the client side,The Tars-PHP client features unified configuration, one-click call, and multiple networking capabilities. Functions support automatic addressing, call reporting, remote logging and SOCKET, SWOOLE synchronization, SWOOLE coroutine network capabilities. In addition, the system reports the time consuming, failure rate, timeout rate, and server exceptions based on the actual network sending and receiving status, facilitating services to discover and locate problems as soon as possible

In terms of binary protocols,Tars-php is a standalone PHP module extension that packages and unpackages binary protocols with both high performance and stability in mind. Through the reasonable design of the interface and completely through the implementation of pure C language, improve performance. By introducing the extended standard testing of PHPT and Valgrind tool testing, more than 80% of the test code was covered to improve stability. This extension improves packaging efficiency by 12-16 times and unpacking efficiency by 9-14 times compared to the original pure PHP packaging and unpacking method.

On the server side,The Tars-PHP server uses SWOOLE as the underlying operating environment, which can be used smoothly with a simple configuration. In addition, the tars-PHP server routes requests through automatically generated annotations, so developers don’t have to worry about implementing their own business logic. In addition to the basic SERVER type, it also provides a complete system of configuration file parsing, service live reporting, pull-and-deliver configuration, feature reporting, and service code packaging, enabling users to realize their own business logic and expand targeted. From the test data, empty HTTP SERVER QPS reached the highest 230 thousand. With the use of the coroutine CLIENT, the QPS for mixed RPC calls were still 21,000, an increase of about 50% compared to the synchronous CLIENT.

In terms of development efficiency,TARS PHP upgraded the new TARS2PHP tool, through the TARS file and TARS2PHP tool, can fully realize the client side and the server side of the code generation, and both ends through the protocol completely decouples, greatly improving the development efficiency.

Taking the practice of China Literature Group as an example, he introduced that Tars-PHP has been verified and used in reading articles for more than one year. Currently, it supports more than a dozen Node HTTP services, more than 40 logical API layer PHP services and timing services, as well as more than 100 background TCP services. The comprehensive improvement of development, operation and maintenance and performance.

In the end, Liang Chen introduced the future planning. Tars-php will support more frameworks and enrich functions while improving stability. He also called on more companies and developers to get involved and work together to make Sars-PHP even better.



Ted Liang,Senior development engineer of China Literature Group, responsible person of Qidian WEB backend architecture. Once worked in Tencent, responsible for the backstage development and optimization of enterprise QQ and QQ official account. As a contributor of Tencent TARS open source project and a member of Tencent TSF development team, he has rich experience in building high-performance WEB background and micro-service governance.