php专区

 首页 > php专区 > PHP应用 > 常用功能 > PHP脚本实现Magento权限设置与缓存清理 - php高级应

PHP脚本实现Magento权限设置与缓存清理 - php高级应

分享到:
【字体:
导读:
          PHP脚本实现Magento权限设置与缓存清理的实例代码有需要的朋友可参考一下 PHP实例代码如下:?php 设置文件644,目录755functionAllDirChmod($dir= ,$dirModes=0755,$fileModes=0644){$d=newRec...

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

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

  1. ## 设置文件644,目录755 
  2. function AllDirChmod( $dir = "./"$dirModes = 0755, $fileModes = 0644 ){ 
  3.    $d = new RecursiveDirectoryIterator( $dir ); 
  4.    foreachnew RecursiveIteratorIterator( $d, 1 ) as $path ){ 
  5.       if$path->isDir() ) chmod$path$dirModes ); 
  6.       else ifis_file$path ) ) chmod$path$fileModes ); 
  7.   } 
  8.  
  9. ## 清除指定目录 
  10. function cleandir($dir) { 
  11.     if ($handle = opendir($dir)) { 
  12.         while (false !== ($file = readdir($handle))) { 
  13.             if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) { 
  14.                 if (unlink($dir.'/'.$file)) { } 
  15.                 else { echo $dir . '/' . $file . ' (file) NOT deleted!'; } 
  16.             } 
  17.             else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) { 
  18.                 cleandir($dir.'/'.$file); 
  19.                 if (rmdir($dir.'/'.$file)) { } 
  20.                 else { echo $dir . '/' . $file . ' (directory) NOT deleted!'; } 
  21.             } 
  22.         } 
  23.         closedir($handle); 
  24.     } 
  25.  
  26. ## 判断目录是否为空 
  27. function isDirEmpty($dir){ 
  28.      return (($files = @scandir($dir)) && count($files) <= 2); 
  29.  
  30. echo "----------------------- CLEANUP START -------------------------
    "
  31. $start = (float) array_sum(explode(' ',microtime())); 
  32. echo "
    *************** SETTING PERMISSIONS ***************
    "
  33. echo "Setting all folder permissions to 755
    "
  34. echo "Setting all file permissions to 644
    "
  35. AllDirChmod( "." ); 
  36. echo "Setting pear permissions to 550
    "
  37. chmod("pear", 550); 
  38.  
  39. echo "
    ****************** CLEARING CACHE ******************
    "
  40.  
  41. if (file_exists("var/cache")) { 
  42.     echo "Clearing var/cache
    "
  43.     cleandir("var/cache"); 
  44.  
  45. if (file_exists("var/session")) { 
  46.     echo "Clearing var/session
    "
  47.     cleandir("var/session"); 
  48.  
  49. if (file_exists("var/minifycache")) { 
  50.     echo "Clearing var/minifycache
    "
  51.     cleandir("var/minifycache"); 
  52.  
  53. if (file_exists("downloader/pearlib/cache")) { 
  54.     echo "Clearing downloader/pearlib/cache
    "
  55.     cleandir("downloader/pearlib/cache"); 
  56.  
  57. if (file_exists("downloader/pearlib/download")) { 
  58.     echo "Clearing downloader/pearlib/download
    "
  59.     cleandir("downloader/pearlib/download"); 
  60.  
  61. if (file_exists("downloader/pearlib/pear.ini")) { 
  62.     echo "Removing downloader/pearlib/pear.ini
    "
  63.     unlink ("downloader/pearlib/pear.ini"); 
  64.  
  65. echo "
    ************** CHECKING FOR EXTENSIONS ***********
    "
  66. If (!isDirEmpty("app/code/local/")) {  
  67.     echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder
    "
  68. If (!isDirEmpty("app/code/community/")) {  
  69.     echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder
    "
  70. $end = (float) array_sum(explode(' ',microtime())); 
  71. echo "
    ------------------- CLEANUP COMPLETED in:"
    . sprintf("%.4f", ($end-$start))." seconds ------------------
    "
  72. ?> 
分享到:
phpExcel数据内存溢出解决办法 - php高级...
phpExcel数据内存溢出解决办法 云平台需要进行excel数据批量导入,使用的是phpExcel工具,小曲同学的代码都写好后,小数据量下测试都没有问题,可是一到正式环境下,数据超过千条,一行十列为一条数据,就报内存超出. 先看实例,代码如下:
PHP中常用的缓存技术介绍 - php高级应用
PHP中常用的缓存技术介绍 数据缓存:这里所说的数据缓存是指数据库查询缓存,每次访问页面的时候,都会先检测相应的缓存数据是否存在,如果不存在,就连接数据库,得到数据,并把查询结果序列化后保存到文件中,以后同样的查询结果就直接从缓存文件中获得,代码如下:   页面缓存:每次访问...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……