手记

SWOOLE 从入门到放弃之写个小框架(二)

先写个HTTP DEMO

<?php
class Server
{
    public $server;
    public function __construct(){
        $this->server = new swoole_http_server('0.0.0.0',9501);
        $this->server->on('start', [$this, 'onStart']);
        $this->server->on('request' ,[$this,'onRequest']);
        $this->server->start();
    }

    public function onStart($server){
        echo "服务启动  http://0.0.0.0:9501",PHP_EOL;
    }

    public function onRequest($request,$response){
        $response->end("hello");
    }

    public function onClose($server,$fd){
    }

}

new Server();

试运行一下

0人推荐
随时随地看视频
慕课网APP