Clear.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /**
  7. * 首页控制器
  8. * Class Clear
  9. * @package app\admin\controller
  10. *
  11. */
  12. class Clear extends AuthController
  13. {
  14. public function index()
  15. {
  16. return $this->fetch();
  17. }
  18. public function refresh_cache(){
  19. if(function_exists('shell_exec')){
  20. `php think optimize:schema`;
  21. `php think optimize:autoload`;
  22. `php think optimize:route`;
  23. `php think optimize:config`;
  24. }else if(function_exists('exec')){
  25. exec('php think optimize:schema');
  26. exec('php think optimize:autoload');
  27. exec('php think optimize:route');
  28. exec('php think optimize:config');
  29. }
  30. return Json::successful('数据缓存刷新成功!');
  31. }
  32. public function delete_cache(){
  33. $this->delDirAndFile("./runtime/temp");
  34. $this->delDirAndFile("./runtime/cache");
  35. return Json::successful('清除缓存成功!');
  36. }
  37. public function delete_log(){
  38. $this->delDirAndFile("./runtime/log");
  39. return Json::successful('清除日志成功!');
  40. }
  41. function delDirAndFile($dirName,$subdir=true){
  42. if ($handle = opendir("$dirName")){
  43. while(false !== ($item = readdir($handle))){
  44. if($item != "." && $item != ".."){
  45. if(is_dir("$dirName/$item"))
  46. $this->delDirAndFile("$dirName/$item",false);
  47. else
  48. @unlink("$dirName/$item");
  49. }
  50. }
  51. closedir($handle);
  52. if(!$subdir) @rmdir($dirName);
  53. }
  54. }
  55. }