一、代码部分

<?php
/**
 * 传统:nginx <-> php-fpm(fast-cgi process manager) <-> php
 * swoole:http-request -> swoole
 */
use Swoole\Http\Server;

$http = new Server("127.0.0.1", 9501);

// 若请求的是静态内容则直接返回
$http->set([
    'enable_static_handler' => true,
    'document_root' => '/root/www/html'
]);

$http->on('request', function ($request, $response) {
    // 设置cookie
    $response->cookie('swoole', 'http_server', time()+1800);
    $msg = print_r($request->get, true);
    $response->end("<h1> - {$msg} - </h1>");
});
$http->start();

可通过 命令行

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

# curl http://127.0.0.1 9501 

或者

浏览器 http://127.0.0.1:9501 

进行测试

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄