Git Product home page Git Product logo

tsf's Introduction

项目目前是存档状态,感谢您对腾讯开源项目的关注!您可以继续fork后更新迭代,感谢理解和支持;如果您有其他疑问,建议请发送邮件:[email protected] 与我们联系


Tencent Server Framework

Overview

Tencent Server Framework is a coroutine and Swoole based server framework for fast server deployment which developed by Tencent engineers.

Features

  • PHP 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

Requirements

  • php5.5+
  • Swoole1.7.18+
  • linux,OS X

Installation

Introduction

  • Tencent Server Framework can help you to start your server quickly,you just need to set a few settings

Server config

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'

How to start your server

cd /root/tsf/bin/
php swoole testHttpServ start
  • Support Cmds: start,stop,reload,restart,status,shutdown,startall,list

How to use TCP/UDP/HTTP Client

  • we 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 Muticall

  • Beside 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);
    $thirdReq= new Swoole\Client\HTTP("http://www.qq.com");

    $calls ->request($firstReq,'first');             //first request
    $calls ->request($secondReq,'second');             //second request
    $calls ->request($thirdReq,'third');             //third request
    yield $calls;
  }

  var_dump($res)
  

Concect to mysql async

    $sql = new Swoole\Client\MYSQL(array('host' => '127.0.0.1', 'port' => 3345, 'user' => 'root', 'password' => 'root', 'database' => 'test', 'charset' => 'utf-8',));
    $ret = (yield $sql ->query('show tables'));
    var_dump($ret);
    $ret = (yield $sql ->query('desc test'));
    var_dump($ret);
    

Router

  • We support individuation route rules
  • now we realize some universal route rules and restful rules
  • besides that, we also support default GET parameter
  URL                                       METHOD       CONTROLLER  ACTION
  http://127.0.0.1:80/Test?h=1              ANY     ==>  TestController/ActionIndex

  http://127.0.0.1:80/Test/send?h=1         ANY     ==>  TestController/ActionSend
  Restful
  http://127.0.0.1:80/rest                  GET     ==>  TestController/ActionList
  http://127.0.0.1:80/rest/Test/22          GET     ==>  TestController/ActionView
                                                         Get['id']=22
  http://127.0.0.1:80/rest/Test             POST    ==>  TestController/ActionCreate
  http://127.0.0.1:80/rest/Test/22          PUT     ==>  TestController/ActionUpdate
                                                         Get['id']=22
  http://127.0.0.1:80/rest/Test/22          DELETE  ==>  TestController/ActionDelete
                                                         Get['id']=22
  http://127.0.0.1:80/rest/Test/send/1/li   GET     ==>  TestController/ActionSend
                                                         Get['cid']=1 Get['name']=li

Performance

Contribution

Your contribution to TSF development is very welcome!

You may contribute in the following ways:

tsf's People

Contributors

chalesi avatar dcant avatar lexsiw avatar seumadwolf avatar sukui avatar tencent-adm avatar winterswang avatar xyzhu1120 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tsf's Issues

路由问题

我想问下这个框架路由是怎么实现的,代码在哪里

发现一个bug

看源码的时候,总觉得/Coroutine/Scheduler.php和Coroutine/Task.php有bug,
于是进行了测试,为了测试方便,我把worker_num设置为1;
我在测试的控制器里有两个action。分别为action1和action2
action1为慢速的请求,一般需要2s才能回数据
action2响应比较快,都在几毫秒内完成。

我用两个客户端先后访问action1和action2,action2能返回数据,但是action1则卡着不动,一直没有响应。

原因应该是Coroutine/Task.php里处理异步io的时候,直接return,处理下一个请求;当慢请求有数据返回的时候需要进行回调,但是Coroutine/Scheduler.php里的run方法的task对象已经被销毁了,无法给客户端返回数据。

How to use muticallTest

What's the complete example code about muticallTest()?
The code can not run in readme.md.

server启动后如何访问

直接部署的github上的源码
ubuntu 14
[server]
;server type
type = http
; port
listen[] = 8080
; index.php path
root = '/var/www/examples/src/index.php'
;php path
php = '/usr/php/bin/php'

[setting]
; worker num
worker_num = 8
; task num
task_worker_num = 0
dispatch_mode = 2
daemonize = 1

;post max length
package_max_length = 12582912
buffer_output_size= 12582912
; log path
log_file = '/data/log/test.log'

heartbeat_check_interval = 60
heartbeat_idle_time = 600

;close eof check
open_eof_check = false
open_eof_split = false


启动后
root 4460 0.1 0.2 81132 9952 ? Ss 05:08 0:02 Swoole-Controller
Swoole-Controller is [RUNNING]
Server Name is testHttpServ and php start path is /usr/php/bin/php


接下来如何访问?

error

php swoole.php testHttpServ start

PHP Fatal error: Class Swoole\Network\TcpServer contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Swoole\Server\Driver::run, Swoole\Server\Driver::setProtocol) in /data/tsf/lib/Swoole/Network/TcpServer.php on line 7
/usr/bin/php70 testHttpServ start [FAIL]

是不是不兼容新版的swoole了?

现在启动会报错。
好像是\Swoole\Network\TcpServer extends了\Swoole\Server这个类,这个父类本来是一个自定义类,但是新版的swoole添加了命名空间支持,所以实际上\Swoole\Server指向了swoole_server。
期望能修复下~

规范注释

代码里怎么那么多注释呀,不像大厂的作风。

有点意思

在企鹅什么项目中用到了呢?
PHP , Swoole 版本太低了点,何时抽空升级下?

为什么不写中文的readme

难道这是个美帝写的吗?为什么readme的文档不是中文的?
作为天朝人,感觉第一文档还是应该写中文的好吧,先解决国内,然后才是走向世界吧!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.