optimize.ctrl.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->func('cache');
  8. $dos = array('opcache');
  9. $do = in_array($do, $dos) ? $do : 'index';
  10. if ($do == 'opcache') {
  11. opcache_reset();
  12. itoast('清空缓存成功', url('system/optimize'), 'success');
  13. } else {
  14. $cache_type = cache_type();
  15. $clear = array('url' => url('system/updatecache'), 'title' => '更新缓存');
  16. $extensions = array(
  17. 'memcache' => array(
  18. 'support' => extension_loaded('memcache'),
  19. 'status' => $cache_type == 'memcache',
  20. 'clear' => $clear
  21. ),
  22. 'redis' => array(
  23. 'support' => extension_loaded('redis'),
  24. 'status' => $cache_type == 'redis',
  25. 'clear' => $clear
  26. ),
  27. 'eAccelerator' => array(
  28. 'support' => function_exists('eaccelerator_optimizer'),
  29. 'status' => function_exists('eaccelerator_optimizer'),
  30. ),
  31. 'opcache' => array(
  32. 'support' => function_exists('opcache_get_configuration'),
  33. 'status' => ini_get('opcache.enable') || ini_get('opcache.enable_cli'),
  34. 'clear' => array(
  35. 'url' => url('system/optimize/opcache'),
  36. 'title' => '清空缓存',
  37. )
  38. )
  39. );
  40. $slave = $_W['config']['db'];
  41. $setting = $_W['config']['setting'];
  42. if ($extensions['memcache']['status']) {
  43. $memobj = cache_memcache();
  44. if (!empty($memobj) && method_exists($memobj, 'getExtendedStats')) {
  45. $status = $memobj->getExtendedStats();
  46. if (!empty($status)) {
  47. foreach ($status as $server => $row) {
  48. $data_status[] = '已用:' . round($row['bytes'] / 1048576, 2) . ' M / 共:' . round($row['limit_maxbytes'] / 1048576) . ' M';
  49. }
  50. $extensions['memcache']['extra'] = ', ' . implode(', ', $data_status);
  51. }
  52. }
  53. }
  54. if ($extensions['redis']['status']) {
  55. $redisobj = cache_redis();
  56. if (!empty($redisobj) && method_exists($redisobj, 'info')) {
  57. $status = $redisobj->info();
  58. if (!empty($status)) {
  59. $extensions['redis']['extra'] = '消耗峰值:' . round($status['used_memory_peak'] / 1048576, 2) . ' M/ 内存总量:' . round($status['used_memory'] / 1048576, 2) . ' M';
  60. }
  61. }
  62. }
  63. template('system/optimize');
  64. }