7月18日杭州 OSC 源创会正在报名,送机械键盘和开源无码内裤
tsf (Tencent Server Framework) 是腾讯公司推出的 PHP 协程方案,基于 Swoole+PHP Generator 实现的 Coroutine。Tencent Server Framework 是快速服务器部署框架,PHP 现在可以像 Golang 一样用协程实现高并发服务器,同时支持同步阻塞,异步非阻塞回调,协程这 3 种 IO 模型。
主要特性:
基于 PHP,相比 C++ 开发更高效
基于 Swoole 扩展,强大的异步 IO
支持 PHP coroutine
支持服务器监控器和提供接口
要求:
php5.5+
Swoole1.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); }