创建http服务器

<?php
$http = new swoole_http_server('0.0.0.0',8811);
/*
获取静态资源
如果我们把1.html放进data文件夹中,就可以直接输出,后面的方法将不再执行
*/
$http->set([
    'enable_static_handler'=>true,
    'document_port'=>'/home/work/hdtocs/swooler_mooc/data'//静态资源的存放位置
]);
$http->on('request',function($request,$response){
    printt_r($request->get);//获取get传过来的参数,只能在终端显示
    $response->cookie('singwa','xssss',time()+1800);//设置cookie
    $response->end('sss'.json_encode($request->get));//输出在浏览器,end()函数中只能是字符串
});
$http->start();
/* end操作后将向客户端浏览器发送HTML内容 end只能调用一次,如果需要分多次向客户端发送数据,请使用write方法 */
原文地址:https://www.cnblogs.com/hanmengya/p/10935752.html