Heim  >  Artikel  >  php教程  >  PHP脚本实现Magento权限设置与缓存清理

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

WBOY
WBOYOriginal
2016-05-25 16:43:31783Durchsuche

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

<?php
## 设置文件644,目录755 
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){ 
   $d = new RecursiveDirectoryIterator( $dir ); 
   foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ 
      if( $path->isDir() ) chmod( $path, $dirModes ); 
      else if( is_file( $path ) ) chmod( $path, $fileModes ); 
  } 
} 
 
## 清除指定目录 
function cleandir($dir) { 
    if ($handle = opendir($dir)) { 
        while (false !== ($file = readdir($handle))) { 
            if ($file != &#39;.&#39; && $file != &#39;..&#39; && is_file($dir.&#39;/&#39;.$file)) { 
                if (unlink($dir.&#39;/&#39;.$file)) { } 
                else { echo $dir . &#39;/&#39; . $file . &#39; (file) NOT deleted!<br />&#39;; } 
            } 
            else if ($file != &#39;.&#39; && $file != &#39;..&#39; && is_dir($dir.&#39;/&#39;.$file)) { 
                cleandir($dir.&#39;/&#39;.$file); 
                if (rmdir($dir.&#39;/&#39;.$file)) { } 
                else { echo $dir . &#39;/&#39; . $file . &#39; (directory) NOT deleted!<br />&#39;; } 
            } 
        } 
        closedir($handle); 
    } 
} 
 
## 判断目录是否为空 
function isDirEmpty($dir){ 
     return (($files = @scandir($dir)) && count($files) <= 2); 
} 
 
echo "----------------------- CLEANUP START -------------------------<br/>"; 
$start = (float) array_sum(explode(&#39; &#39;,microtime())); 
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>"; 
echo "Setting all folder permissions to 755<br/>"; 
echo "Setting all file permissions to 644<br/>"; 
AllDirChmod( "." ); 
echo "Setting pear permissions to 550<br/>"; 
chmod("pear", 550); 
 
echo "<br/>****************** CLEARING CACHE ******************<br/>"; 
 
if (file_exists("var/cache")) { 
    echo "Clearing var/cache<br/>"; 
    cleandir("var/cache"); 
} 
 
if (file_exists("var/session")) { 
    echo "Clearing var/session<br/>"; 
    cleandir("var/session"); 
} 
 
if (file_exists("var/minifycache")) { 
    echo "Clearing var/minifycache<br/>"; 
    cleandir("var/minifycache"); 
} 
 
if (file_exists("downloader/pearlib/cache")) { 
    echo "Clearing downloader/pearlib/cache<br/>"; 
    cleandir("downloader/pearlib/cache"); 
} 
 
if (file_exists("downloader/pearlib/download")) { 
    echo "Clearing downloader/pearlib/download<br/>"; 
    cleandir("downloader/pearlib/download"); 
} 
 
if (file_exists("downloader/pearlib/pear.ini")) { 
    echo "Removing downloader/pearlib/pear.ini<br/>"; 
    unlink ("downloader/pearlib/pear.ini"); 
} 
 
echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>"; 
If (!isDirEmpty("app/code/local/")) {  
    echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>"; 
} 
If (!isDirEmpty("app/code/community/")) {  
    echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>"; 
} 
$end = (float) array_sum(explode(&#39; &#39;,microtime())); 
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";


文章地址:

转载随意^^请带上本文地址!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn