swoole面向对象的写法

<?php
/**
 * 
 */
class Http
{
    
    protected $http;
    
    protected $config = [
        'worker_num' => 1
    ];
    public function __construct($ip,$port)
    {
        echo $ip.':'.$port;
        $this->http = new Swoole\Http\Server($ip,$port);
        $this->http->set($this->config);
        $this->http->on('request',[$this,'request']);
    }

    public function request($request,$response){
        var_dump(0);
        var_dump($request->get,$request->post);
        $response->header("Content-Type","text/html;charset=utf-8");
        $response->end("<h1>Hello Swoole. #".rand(1000,9000)."</h1>");
    }

    public function start(){
        $this->http->start();    
    }

}

$http = new Http('0.0.0.0',9501);
$http->start();

王如棋博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论