zoukankan      html  css  js  c++  java
  • 【swoole http_server】


    <?php class Http{ CONST PORT = 8090; CONST HOST = '0.0.0.0'; CONST ENABLE_STATIC_HANDLER = TRUE; CONST DOCUMENT_ROOT = '/www/wwwroot/swoole'; private $http = null; public function __construct() { $this->http = new swoole_http_server(self::HOST,self::PORT); $this->http->set( [ 'enable_static_handler'=>self::ENABLE_STATIC_HANDLER, 'document_root' =>self::DOCUMENT_ROOT, ] ); $this->http->on('request',[$this,'onRequest']); $this->http->start(); } public function onRequest($request,$response) { var_dump($request->get,$request->post); $response->header("Content-Type", "text/html; charset=utf-8"); $response->end("<h1>Hello Swoole".rand(1000,9999)."</h1>"); } }; new Http();

    启动服务

    [root@iz2ze2rkosydwj6j4rmp7hz swoole]# php http_server.php 

    在浏览器访问:http://39.105.181.143:8090/index.html

    在浏览器访问:http://39.105.181.143:8090/

    总结:

      可能存在的问题:

      服务器需要设置安全组,并且打开防火墙

      如果不能访问静态资源:

        可能原因是因为swoole版本太低(我第一个失败的版本是1.7.21,搞了很久都不行,最后安装了官方最新版本4.2.2一切ok

  • 相关阅读:
    Redis 基本数据类型
    Redis的安装
    Redis介绍
    JavaWeb Servlet
    深入理解JVM1
    JavaWeb Request和Response
    移动端获取屏幕宽度
    meta标签大全(荐)
    网页加载进度条
    每个JavaScript程序员都需要知道的5个数组方法
  • 原文地址:https://www.cnblogs.com/fyandy/p/10055042.html
Copyright © 2011-2022 走看看