当前位置:首页 > PHP教程 > php高级应用 > 列表

PHP脚本实现Magento权限设置与缓存清理

发布:smiling 来源: PHP粉丝网  添加日期:2014-07-30 11:25:32 浏览: 评论:0 

PHP脚本实现Magento权限设置与缓存清理的实例代码有需要的朋友可参考一下.PHP实例代码如下:

  1. <?php
  2. ## 设置文件644,目录755 
  3. function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){ 
  4.    $d = new RecursiveDirectoryIterator( $dir ); 
  5.    foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ 
  6.       if( $path->isDir() ) chmod( $path, $dirModes ); 
  7.       else if( is_file( $path ) ) chmod( $path, $fileModes ); 
  8.   } 
  9. } 
  10.  
  11. ## 清除指定目录 
  12. function cleandir($dir) { 
  13.     if ($handle = opendir($dir)) { 
  14.         while (false !== ($file = readdir($handle))) { 
  15.             if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) { 
  16.                 if (unlink($dir.'/'.$file)) { } 
  17.                 else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; } 
  18.             } 
  19.             else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) { 
  20.                 cleandir($dir.'/'.$file); 
  21.                 if (rmdir($dir.'/'.$file)) { } 
  22.                 else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; } 
  23.             } 
  24.         } 
  25.         closedir($handle); 
  26.     } 
  27. } 
  28.  
  29. ## 判断目录是否为空 
  30. function isDirEmpty($dir){ 
  31.      return (($files = @scandir($dir)) && count($files) <= 2); 
  32. } 
  33.  
  34. echo "----------------------- CLEANUP START -------------------------<br/>"; 
  35. $start = (float) array_sum(explode(' ',microtime())); 
  36. echo "<br/>*************** SETTING PERMISSIONS ***************<br/>"; 
  37. echo "Setting all folder permissions to 755<br/>"; 
  38. echo "Setting all file permissions to 644<br/>"; 
  39. AllDirChmod( "." ); 
  40. echo "Setting pear permissions to 550<br/>"; 
  41. chmod("pear", 550); 
  42.  
  43. echo "<br/>****************** CLEARING CACHE ******************<br/>"; 
  44.  
  45. if (file_exists("var/cache")) { 
  46.     echo "Clearing var/cache<br/>"; 
  47.     cleandir("var/cache"); 
  48. } 
  49.  
  50. if (file_exists("var/session")) { 
  51.     echo "Clearing var/session<br/>"; 
  52.     cleandir("var/session"); 
  53. } 
  54.  
  55. if (file_exists("var/minifycache")) { 
  56.     echo "Clearing var/minifycache<br/>"; 
  57.     cleandir("var/minifycache"); 
  58. } 
  59.  
  60. if (file_exists("downloader/pearlib/cache")) { 
  61.     echo "Clearing downloader/pearlib/cache<br/>"; 
  62.     cleandir("downloader/pearlib/cache"); 
  63. } 
  64.  
  65. if (file_exists("downloader/pearlib/download")) { 
  66.     echo "Clearing downloader/pearlib/download<br/>"; 
  67.     cleandir("downloader/pearlib/download"); 
  68. } 
  69.  
  70. if (file_exists("downloader/pearlib/pear.ini")) { 
  71.     echo "Removing downloader/pearlib/pear.ini<br/>"; 
  72.     unlink ("downloader/pearlib/pear.ini"); 
  73. } 
  74.  
  75. echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>"; 
  76. If (!isDirEmpty("app/code/local/")) {  
  77.     echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>"; 
  78. } 
  79. If (!isDirEmpty("app/code/community/")) {  
  80.     echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>"; 
  81. } 
  82. $end = (float) array_sum(explode(' ',microtime())); 
  83. echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>"; 
  84. ?> 

Tags: PHP缓存 Magento 权限设置

分享到: