swoole学习第四讲(创建一个httpServer)

创建9501端口映射
      ports:
        - "${WORKSPACE_SSH_PORT}:22"
        - "9501:9501"
创建httpServer
// 创建httpServer
$http = new swoole_http_server('0.0.0.0', 9501);
// 监听server启动事件
$http->on('start', function ($serv) {
    echo "Start \n";
});

// 监听request请求
$http->on('request', function ($request, $response) {
    var_dump($request->get, $request->post);
    $response->header("Content-Type", "text/html; charset=utf-8");
    $response->end("

Hello Swoole. #

" . rand(1000, 9999) . ""); }); $http->start();
进入workspace容器

docker-compose exec workspace bash //进入workspace
php http_server.php // 启动httpSerer

访问 http://localhost:9501

你可能感兴趣的:(swoole学习第四讲(创建一个httpServer))