Example #1
0
 public function gc($time)
 {
     $path = $this->getPath();
     $files = Dir::tree($path);
     foreach ($files as $file) {
         if (false !== strpos($file, 'sess_')) {
             if (fileatime($file) < time() - $this->gcTime) {
                 unlink($file);
             }
         }
     }
     return true;
 }
Example #2
0
 /**
  * 加载资源包文件
  * @author  xiaohuihui  <*****@*****.**>
  * @param string $srcPath
  * @param string $defaultModel
  * @param string $Lang
  */
 public static function load($srcPath = "", $defaultModel = "", $Lang = "zh")
 {
     if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $langstr = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "";
         switch (strtolower($langstr[0] . $langstr[1])) {
             case 'zh':
                 $Lang = 'zh';
                 break;
             case 'en':
                 $Lang = 'en';
                 break;
             default:
                 $Lang = 'zh';
         }
     }
     if ($srcPath == "") {
         $srcPath = SsdPHP::getRootPath() . "resources/lang/" . $Lang . "/";
     }
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($srcPath . $defaultModel));
     if (SsdPHP::isDebug() == false) {
         fileatime($srcPath);
         if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($srcPath)) {
             self::$LanguageAry = (include $tmpfile);
             return;
         }
     }
     $files = Dir::tree($srcPath, "/.php\$/");
     $Language = array();
     if ($defaultModel != "") {
         $langFile = $srcPath . $defaultModel . ".php";
         if (is_file($langFile)) {
             $Language = (include "{$langFile}");
         }
     } elseif (!empty($files)) {
         foreach ($files as $file) {
             $Language += (include "{$file}");
         }
     }
     //end if
     self::$LanguageAry = $Language;
     self::$LanguagePath = $srcPath;
     file_put_contents($tmpfile, "<?php return " . var_export($Language, true) . ";?>", LOCK_EX);
     return;
 }
Example #3
0
 /**
  * 加载配置文件
  * @param $configPath 配置文件放置的目录
  * @return array|mixed
  */
 public static function load($configPath)
 {
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($configPath));
     fileatime($configPath);
     if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($configPath) && !SsdPHP::isDebug()) {
         self::$config = (include $tmpfile);
         return;
     }
     $files = Dir::tree($configPath, "/.php\$/");
     $config = array();
     if (!empty($files)) {
         foreach ($files as $file) {
             $config += (include "{$file}");
         }
     }
     self::$config = $config;
     self::$configPath = $configPath;
     file_put_contents($tmpfile, "<?php return " . var_export($config, true) . ";?>", LOCK_EX);
     return;
 }