php think clear 仅清除 cache、log、temp、route 四类缓存,不包括 HTML 缓存和 request_cache;需额外执行 --html 和 --path runtime/request_cache 才能清空全部。

直接运行 php think clear 并不能清空“所有缓存”,它只清理 cache、log、temp、route 四类,不包括 HTML 缓存和 request_cache。真正想清空全部,得组合操作。
哪些缓存会被 php think clear 清掉
该命令默认清除以下四类:
-
cache:runtime/cache/ 下的数据缓存(如
Cache::set()写入的 .php 文件) - log:runtime/log/ 下的日志文件
- temp:runtime/temp/(配置缓存)和 runtime/view/(模板编译缓存)
- route:runtime/route.php(路由缓存,TP5.1.14+ 支持)
注意:php think clear 不会动 runtime/html/(HTML 静态缓存)和 runtime/request_cache/(请求级缓存),这两类需单独处理。
手动补全缺失的两类缓存
若项目启用了 HTML 缓存或请求缓存,必须额外执行:
立即学习“PHP免费学习笔记(深入)”;
- 清 HTML 缓存:
php think clear --html(确认 config 中已设置html_cache_path) - 清请求缓存:
php think clear --path runtime/request_cache(TP5.1+ 支持自定义路径清理)
也可以用脚本一次性跑完:php think clear && php think clear --html && php think clear --path runtime/request_cache
标签缓存和 Redis 缓存要特别对待
Cache::tag() 写入的缓存不会被 clear 命令清除,必须用代码精准清除:
- 清除某个标签:
Cache::clear('user') - 清除全部标签缓存:
Cache::clear()(仅清内存索引,物理文件仍残留) - Redis 场景下:
php think clear --redis(TP6 支持;TP5.1 需手动连 Redis 执行FLUSHDB)
File 驱动的标签缓存,物理文件不会自动删除,建议开发期配合 php think clear --cache + 手动递归删 runtime/cache/ 目录。
安全清理,别碰这些目录
以下目录不在 clear 命令范围内,也绝对不要手动删:
-
runtime/根目录本身(含 route.php、.htaccess 等关键文件) -
runtime/common/(某些扩展写入的共享缓存) -
runtime/session/(除非你确定 session 不重要)
误删可能导致 404、Class not found 或登录态丢失。清理前建议先 du -sh runtime/* | sort -hr 确认空间大户再动手。



















