首頁 >php教程 >php手册 >PHP脚本实现Magento权限设置与缓存清理

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

WBOY
WBOY原創
2016-05-25 16:43:31828瀏覽

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/>";


文章地址:

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn