全部
常见问题
产品动态
精选推荐
功能建议

已处理 待处理 {{opt.name}}
已处理 待处理
分析中 已回复 待规划 {{opt.name}}
分析中 已回复 待规划
PRO V4.1修复 Swoole 环境下路由表清空导致的权限异常

管理 管理 编辑 删除

问题现象

在 Swoole 环境下,执行接口权限列表、权限校验等操作后,可能出现:

  • 后台接口提示无权限访问。
  • 已配置权限的接口仍然无法访问。
  • 部分接口出现路由不存在或 404。
  • 重启 Swoole 后暂时恢复,操作权限功能后再次出现。

问题原因

权限相关代码调用了:

$this->app->route->clear();

该方法会清空当前运行环境中的路由规则。

Swoole Worker 为常驻内存模式,运行期间清空并重新加载路由会影响已经初始化的全局路由表。正确处理方式是直接读取启动时已经加载完成的路由列表,禁止在业务请求中清空、重新注册路由。

修改一:接口权限列表

文件:app/controller/admin/v1/system/SystemMenus.php

方法:public function ruleList($type = 1)

PRO v4.1 原始代码约在第 231 行。找到以下代码:

$this->app->route->setTestMode(true);
$this->app->route->clear();
$path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR;
$files = is_dir($path) ? scandir($path) : [];
foreach ($files as $file) {
    if (strpos($file, '.php')) {
        include $path . $file;
    }
}
$ruleList = $this->app->route->getRuleList();

修改为:

// Swoole Worker 常驻内存,接口列表只能读取已加载路由,禁止清空后重载全局路由表。
$ruleList = $this->app->route->getRuleList();

也就是删除 setTestMode()、clear()、扫描路由目录和 include 路由文件的代码。

如下图:

9c4b3202607251524217456.png


修改二:权限名称解析

文件:app/services/system/SystemRoleServices.php

方法:public function getRoleName(string $rule, string $method = 'get', string $type = 'admin')

PRO v4.1 原始代码约在第 126 行。找到:

$data = CacheService::redisHandler('system_menus')->remember(md5($path), function () use ($path, $type) {
    $this->app = app();
    $this->app->route->setTestMode(true);
    $this->app->route->clear();
    include $path;
    $ruleList = $this->app->route->getRuleList();

修改为:

$data = CacheService::redisHandler('system_menus')->remember(md5($path), function () use ($type) {
    $this->app = app();
    // Swoole Worker 常驻内存,权限名称解析只能读取已加载路由,禁止清空全局路由表。
    $ruleList = $this->app->route->getRuleList();

如下图:

51802202607251526214301.png

修改完之后重启守护进程

修改完之后重启守护进程

修改完之后重启守护进程

{{voteData.voteSum}} 人已参与
支持
反对
请登录后查看

liusll 最后编辑于2026-07-25 15:27:47

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}} 【已收集】
{{item.floor}}# 沙发 板凳 地板 {{item.floor}}# 【已收集】
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
分享
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
收起 展开更多
查看更多
打赏
已打赏¥{{reward_price}}
28
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服
CRMEB咨询热线 400-8888-794

扫码领取产品资料

功能清单
思维导图
安装教程
CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服