getDispatcher(); $http = new Swoole\Http\Server("0.0.0.0",8085); $http->on('request',function (Request $request,Response $response) use ($dispatcher) { $myRequest = Core\http\Request::init($request); $myResponse = \Core\http\Response::init($response); $routeInfo = $dispatcher->dispatch($myRequest->getMethod(),$myRequest->getUri()); //var_dump($routeInfo); switch($routeInfo[0]) { case FastRoute\Dispatcher::NOT_FOUND: $response->status(404); $response->end(); break; case FastRoute\Dispatcher::METHOD_NOT_ALLOWED: $response->status(405); $response->end(); break; case FastRoute\Dispatcher::FOUND: $handler = $routeInfo[1]; $vars = $routeInfo[2];//参数 $extVars = [$myRequest, $myResponse]; //$response->end($handler($vars, $extVars)); $myResponse->setBody($handler($vars,$extVars)); $myResponse->end(); break; } }); $http->start();