加速配置参考的 https://blog.csdn.net/wl_0912/article/details/89089433
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); }
onMessage的部分需要改一改,我这里实测没有问题