加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2023-07-22 09:16:54 所属栏目:PHP教程 来源:
导读:PHP脚本实现Magento权限设置与缓存清理的实例代码有需要的朋友可参考一下.PHP实例代码如下:

<?php
## 设置文件644,目录755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
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 != '.' && $file != '..' && is_file($dir.'/'.$file)) { 
                if (unlink($dir.'/'.$file)) { } 
                else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; } 
            } 
            else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) { 
                cleandir($dir.'/'.$file); 
                if (rmdir($dir.'/'.$file)) { } 
                else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; } 
            } 
        } 
        closedir($handle); 
    } 

 
## 判断目录是否为空 
function isDirEmpty($dir){ 
     return (($files = @scandir($dir)) && count($files) <= 2); 

 
echo "----------------------- CLEANUP START -------------------------<br/>"; 
$start = (float) array_sum(explode(' ',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(' ',microtime())); 
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>"; 
?> 
 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章