标签:worker tar reac ade close think dump var upper
server\http_server.php
文件<?php
use Swoole\Http\Server as HttpServer;
$http = new HttpServer("127.0.0.1", 8811);
$http->set([
'worker_num' => 5,
'enable_static_handler' => true,
'document_root' => '/home/buinar/www/swoole/livematches/public/static',
//document_root目录下要放一个ico图标,为了防止浏览器请求ico图标时走下面的流程
'log_level' => SWOOLE_LOG_ERROR, // 日志等级 关闭开启debug
'trace_flags' => SWOOLE_TRACE_SERVER, // 日志等级 关闭开启debug
]);
$http->on('WorkerStart',function($server, $worker_id){
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
//加载框架引导文件
require __DIR__ . '/../thinkphp/base.php';
});
$http->on('request', function ($request, $response) use($http){
$_SERVER = [];
if (isset($request->server)) {
foreach ($request->server as $k => $v) {
$_SERVER[strtoupper($k)] = $v;
}
}
if (isset($request->header)) {
foreach ($request->header as $k => $v) {
$_SERVER[strtoupper($k)] = $v;
}
}
$_GET = [];
if (isset($request->get)) {
foreach ($request->get as $k => $v) {
$_GET[$k] = $v;
}
}
$_POST = [];
if (isset($request->post)) {
foreach ($request->post as $k => $v) {
$_POST[$k] = $v;
}
}
ob_start();
try {
// 执行应用并响应
\think\Container::get('app',[APP_PATH])->run()->send();
} catch (\Exception $e) {
echo $e->getMessage();
}
$res = ob_get_clean();
// var_dump($res);
$response->end($res);
// $http->close($response->fd); //关闭客户端连接,重新加载框架内容
});
$http->start();
function path 中的if (is_null($this->path)) {
与}
,这里不需要判断,只注释条件即可,里面的内容不动
function pathinfo中的if (is_null($this->pathinfo)) {
与}
,这里不需要判断,只注释条件即可,里面的内容不动
1.报错:Fatal error: Uncaught think\exception\ErrorException: ob_end_clean(): failed to delete buffer.
加载框架不成功,检查自己是否写正确
2.echo会默认输出两次
这是因为document_root目录下没有ico文件,浏览器自动请求的,上面有解决方案
thinkphp5.1以上官方已经整合swoole了,建议用tp官网整合的swoole。
标签:worker tar reac ade close think dump var upper
原文地址:https://www.cnblogs.com/buinar/p/10860311.html