workerman 加速 laravel 时,只能访问首页吗?我访问所有路由返回的都是首页内容,如何访问某个路由内容呢?

aq1290800466
2390 1 0
1个回答

kiddyu

onMessage的部分需要改一改,我这里实测没有问题

public function onMessage($connection, $request)
    {
        $files = $request->file();
        $files = is_array($files) ? array_filter($files) : $files;

        $server = $_SERVER;
        $server['REQUEST_URI'] = $request->uri();
        $server['DOCUMENT_URI'] = $request->path();
        $server['SCRIPT_NAME'] = $request->path();
        $server['QUERY_STRING'] = $request->queryString();
        $server['REQUEST_METHOD'] = $request->method();
        $server['REMOTE_ADDR'] = $connection->getRemoteIp();

        $headers = $request->header();
        foreach ($headers as $k => $v) {
            $server['HTTP_' . str_replace('-', '_', strtoupper($k))] = $v;
        }

        ob_start();//启用缓存区

        //加载laravel请求核心模块
        $kernel = app()->make(\Illuminate\Contracts\Http\Kernel::class);
        $laravelResponse = $kernel->handle(
            $laravelRequest = \Illuminate\Http\Request::createFromBase(new Request(
                $request->get(),
                $request->post(),
                [],
                $request->cookie(),
                $files,
                $server,
                $request->rawBody()
            ))
        );
        $laravelResponse->send();
        $kernel->terminate($laravelRequest, $laravelResponse);

        $res = ob_get_contents();//获取缓存区的内容
        ob_end_clean();//清除缓存区

        //输出缓存区域的内容
        $connection->send($res);
    }
  • 暂无评论
年代过于久远,无法发表回答
×
🔝