thinkphp 7.0 尚未发布,当前实际使用的是 tp6.x;php think clear 默认仅清 cache/log/session/trace 四类,不包括 view 和 route.php,需用 --all 或 clear:template、route:clear 等精准命令。

默认命令只清四类,常被误判为“没清干净”
执行 php think clear 默认仅删除:
– runtime/cache/
– runtime/log/
– runtime/session/
– runtime/trace/
⚠️ 不包含:runtime/view/(模板缓存) 和 runtime/route.php(路由缓存) —— 这正是改了模板仍不刷新、新增路由报 404 的主因。
真正快速生效的清理组合
- 全量清理(开发环境推荐):php think clear --all → 彻底清空整个 runtime/ 目录(含 view/、route.php、temp/ 等)
-
精准清理(生产环境更安全):
- 模板不更新?→ php think clear:template(TP6.1+ 支持)
- 路由 404?→ php think route:clear
- 编译缓存(如 config、lang 编译文件)卡住?→ php think clear --temp
- Redis 缓存同步清:若同时用了 Redis 做数据缓存,需额外执行 php think cache:clear --driver=redis(需自定义命令或手动调用 Cache::clear('redis'))
代码中触发清理(适合后台按钮或调试接口)
不要直接用 Cache::clear() —— 它只清缓存驱动数据,不影响 runtime 文件。
要删文件,请用:
// 清模板缓存(安全路径拼接)
use think\facade\Env;
use think\helper\Dir;
Dir::delete(Env::get('runtime_path') . 'view');
同理可清理:cache、temp、route.php(需单独 unlink)等目录或文件。
注意事项
– 生产环境避免在 HTTP 请求中执行全量 runtime 删除,易引发并发写冲突
– 手动删文件时,保留 runtime/.gitignore 和自定义配置文件(如 runtime/app.php)
– Linux 下可临时用 rm -rf runtime/{cache,log,view,route.php} 快速组合清理,但不如命令可控
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











