您好,欢迎访问一九零五行业门户网

TSF:腾讯推出的 PHP 协程方案

tsf:腾讯推出的 php 协程方案
tencent server framework
overviewtencent server framework is a coroutine and swoole based server framework for fast server deployment which developed by tencent engineers.
featuresphp based. compared with c++, the framework is more efficient in developing and programing.
based on swoole extension. powerful async io, timers and other infrastructure capacity can be used in this framework.
support php coroutine. synchronous programing is possible using the coroutine schedule system, and can lead to the similar server capability with that of server deveoped in an asynchronous way.
support server monitor and provide interface to add more rules
requirementsphp5.5+
swoole1.7.18+
linux,os x
installationphp install
swoole extension install
introductiontencent server framework can help you to start your server quickly,you just need to set a few settings
server configvim server.ini[server]; server type:tcp,udp,httptype = http; portlisten[] = 12312; entrance fileroot = '/data/web_deployment/serv/test/index.php'; php start pathphp = '/usr/local/php/bin/php'[setting]; worker process numworker_num = 16; task process numtask_worker_num = 0; dispatch modedispatch_mode = 2; daemonizedaemonize = 1; system loglog_file = '/data/log/test.log'
how to start you servercd /root/tsf/bin/ php swoole testhttpserv start
support cmds: start,stop,reload,restart,status,shutdown
how to use tcp/udp/http clientwe support different network protocols: 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); }
how to use muticallbeside that,we also support muticall:
you can use muticall to send tcp,udp packets at the sametime
when all the requests come back,return to interrupt
$res = (yield $this->muticalltest()); public function muticalltest(){ $calls=new swoole\client\multi(); $firstreq=new swoole\client\tcp($ip, $port, $data, $timeout); $secondreq=new swoole\client\udp($ip, $port, $data, $timeout); $calls ->request($firstreq,'first'); //first request $calls ->request($secondreq,'second'); //second request yield $calls; } var_dump($res)
以上就是tsf:腾讯推出的 php 协程方案的内容。
其它类似信息

推荐信息