Clear.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use service\CacheService;
  5. use service\JsonService as Json;
  6. use think\Log;
  7. use think\Cache;
  8. /**
  9. * 首页控制器
  10. * Class Clear
  11. * @package app\admin\controller
  12. *
  13. */
  14. class Clear extends AuthController
  15. {
  16. public function index()
  17. {
  18. return $this->fetch();
  19. }
  20. /**
  21. * 刷新数据缓存
  22. */
  23. public function refresh_cache(){
  24. `php think optimize:schema`;
  25. `php think optimize:autoload`;
  26. `php think optimize:route`;
  27. `php think optimize:config`;
  28. return Json::successful('数据缓存刷新成功!');
  29. }
  30. /**
  31. * 删除缓存
  32. */
  33. public function delete_cache(){
  34. Cache::clear();
  35. array_map('unlink', glob(TEMP_PATH . '/*.php'));
  36. return Json::successful('清除缓存成功!');
  37. }
  38. /**
  39. * 删除日志
  40. */
  41. public function delete_log(){
  42. array_map('unlink', glob(LOG_PATH . '/*.log'));
  43. $this->delDirAndFile(LOG_PATH);
  44. return Json::successful('清除日志成功!');
  45. }
  46. function delDirAndFile($dirName,$subdir=true){
  47. if ($handle = opendir("$dirName")){
  48. while(false !== ($item = readdir($handle))){
  49. if($item != "." && $item != ".."){
  50. if(is_dir("$dirName/$item"))
  51. $this->delDirAndFile("$dirName/$item",false);
  52. else
  53. @unlink("$dirName/$item");
  54. }
  55. }
  56. closedir($handle);
  57. if(!$subdir) @rmdir($dirName);
  58. }
  59. }
  60. }