TSF基于协程和 Swoole 驱动的高性能 PHP 框架
TSF 是腾讯开源的一套基于协程和 Swoole 驱动的高性能 PHP 框架,可以帮助开发者快速开发和部署具备高 IO 吞吐能力的 HTTP/TCP/UDP 服务。
TSF 具备以下特点:
-
基于 PHP,相比 C++ 等语言具有更高的开发效率
-
基于 Swoole 强大的异步 IO 、定时器能力,极大的扩展了框架能力
-
实现了 PHP 协程能力,通过同步的开发方式就可以实现异步 IO 的能力
-
支持服务监控恢复能力
要求:
-
php 5.5 +
-
Swoole 1.7.18 +
-
linux、OS X
服务器配置:
vim server.ini [server] ;server type:tcp,udp,http type = http ; port listen[] = 12312 ; entrance file root = '/data/web_deployment/serv/test/index.php' ;php start path php = '/usr/local/php/bin/php' [setting] ; worker process num worker_num = 16 ; task process num task_worker_num = 0 ; dispatch mode dispatch_mode = 2 ; daemonize daemonize = 1 ; system log log_file = '/data/log/test.log'
启动服务器:
cd /root/tsf/bin/ php swoole testHttpServ start
使用 TCP/UDP/HTTP 客户端:
$tcpReturn=(yield $this->tcpTest()); $udpReturn=(yield $this->udpTest()); $httpReturn=(yield $this->httpTest()); public function tcpTest(){ $ip = '127.0.0.1'; $port = '9905'; $data = 'test'; $timeout = 0.5; //second yield new Swoole\Client\TCP($ip, $port, $data, $timeout); } public function udpTest(){ $ip = '127.0.0.1'; $port = '9905'; $data = 'test'; $timeout = 0.5; //second yield new Swoole\Client\UDP($ip, $port, $data, $timeout); } public function httpTest(){ $url='http://www.qq.com'; $httpRequest= new Swoole\Client\HTTP($url); $data='testdata'; $header = array( 'Content-Length' => 12345, ); yield $httpRequest->get($url); //yield $httpRequest->post($path, $data, $header); }
评论