LLEARNING NOTES

技术 · 思考 · 实践 · 成长

首页/Swoole/正文

Swoole HTTP面向对象封装

Swoole646 次阅读

<?php

 class HTTP{

        private $http = null;

        public function __construct(){

                $this->http = new Swoole\Http\Server('0.0.0.0', 9501);


                /*

                $this->http->set([

                        'worker_num'    => 4,     // worker process num

                        'max_request'   => 50,

                ]);

                */

                $this->http->on('request',[$this,"onRequest"]);

                $this->http->start();

        }




        public function onRequest($request, $response){

                 $response->header('Content-Type', 'text/html; charset=utf-8');

                 $response->end('<h1>Hello Swoole. #' . rand(1000, 9999) . '</h1>');

        }

}


new HTTP();



# php HTTP.php



如果出现无法访问情况,注意查看端口号开放

访问http://42.192.180.238:9501/

Hello Swoole. #9853


热爱可抵岁月漫长, 温柔可挡艰难时光。

评论交流

理性讨论,共同进步
验证码

相关文章

继续阅读