示例#1
0
 public function connect($hostConf)
 {
     $fileStore = new LtStoreFile();
     $fileStore->prefix = 'LtCache-file';
     $fileStore->useSerialize = true;
     $fileStore->init();
     return $fileStore;
 }
示例#2
0
 /**
  * connect
  * @param array $hostConf
  * @return \LtStoreFile
  */
 public function connect($hostConf)
 {
     $fileStore = new LtStoreFile();
     $fileStore->prefix = 'LtCache-file';
     if (isset($hostConf['host'])) {
         $fileStore->storeDir = $hostConf["host"];
     }
     $fileStore->init();
     return $fileStore;
 }
 public function testPerformance()
 {
     // 准备autoloadPath
     $autoloadPath = array(dirname(__FILE__) . "/test_data/class_dir_1", dirname(__FILE__) . "/test_data/class_dir_2", dirname(__FILE__) . "/test_data/function_dir_1", dirname(__FILE__) . "/test_data/function_dir_2");
     /**
      * 用LtStoreFile作存储层提升性能
      */
     $cacheHandle = new LtStoreFile();
     $prefix = sprintf("%u", crc32(serialize($autoloadPath)));
     $cacheHandle->prefix = 'Lotus-' . $prefix;
     $cacheHandle->init();
     /**
      * 运行autoloader成功加载一个类
      * 这是为了证明:使用LtCache作为LtAutoloader的存储,功能是正常的
      */
     $autoloader = new LtAutoloader();
     $autoloader->devMode = false;
     // 关闭开发模式
     $autoloader->storeHandle = $cacheHandle;
     $autoloader->autoloadPath = $autoloadPath;
     $autoloader->init();
     $this->assertTrue(class_exists("HelloWorld"));
     /**
      * 运行1500次,要求在1秒内运行完
      */
     $base_memory_usage = memory_get_usage();
     $times = 1500;
     $startTime = microtime(true);
     for ($i = 0; $i < $times; $i++) {
         $autoloader = new LtAutoloader();
         $autoloader->devMode = false;
         // 关闭开发模式
         $autoloader->storeHandle = $cacheHandle;
         $autoloader->autoloadPath = $autoloadPath;
         $autoloader->init();
         unset($autoloader);
     }
     $endTime = microtime(true);
     $totalTime = round($endTime - $startTime, 6);
     $averageTime = round($totalTime / $times, 6);
     $memory_usage = memory_get_usage() - $base_memory_usage;
     $averageMemory = formatSize($memory_usage / $times);
     $memory_usage = formatSize($memory_usage);
     if (LOTUS_UNITTEST_DEBUG) {
         echo "\n---------------------autoloader--------------------------\n";
         echo "times      \t{$times}\n";
         echo "totalTime   \t{$totalTime}s\taverageTime   \t{$averageTime}s\n";
         echo "memoryUsage \t{$memory_usage}\taverageMemory \t{$averageMemory}";
         echo "\n---------------------------------------------------------\n";
     }
     $this->assertTrue(1 > $totalTime);
 }
示例#4
0
 public function connect($hostConf)
 {
     $fileStore = new LtStoreFile();
     if (isset($hostConf['host']) && is_string($hostConf['host'])) {
         $fileStore->cacheFileRoot = $hostConf['host'];
         $fileStore->prefix = 'Ltcache-phps-';
         $fileStore->init();
         return $fileStore;
     } else {
         trigger_error("Must set [host]");
         return false;
     }
 }
 /**
  * 存储resource类型的Value是不支持的,特别是LtStoreFile
  */
 public function testStoreResourceTypeValue()
 {
     $storeHandle = new LtStoreFile();
     $storeHandle->init();
     //创建一个resource类型的变量
     $res = xml_parser_create();
     $this->assertTrue(is_resource($res));
     //存到LtStoreFile里去
     $storeHandle->add("test_key", $res);
     //再取出来就变成int型了,只有resource id (一个整数)成功存入了
     $valueFromStore = $storeHandle->get("test_key");
     $this->assertTrue(is_int($valueFromStore));
     //显然他们不相等
     $this->assertNotEquals($res, $valueFromStore);
 }
 public function testPerformance()
 {
     /**
      * 用LtStoreFile作存储层提升性能
      */
     $cacheHandle = new LtStoreFile();
     $cacheHandle->init();
     // 准备confif_file
     $config_file = dirname(__FILE__) . "/test_data/conf.php";
     /**
      * 运行autoloader成功取到一个配置 
      * 这是为了证明:使用LtCache作为LtConfig的存储,功能是正常的
      */
     $conf = new LtConfig();
     $conf->storeHandle = $cacheHandle;
     $conf->loadConfigFile($config_file);
     $conf->init();
     $this->assertEquals("localhost", $conf->get("db.conn.host"));
     /**
      * 运行100次,要求在1秒内运行完
      */
     $base_memory_usage = memory_get_usage();
     $times = 100;
     $startTime = microtime(true);
     for ($i = 0; $i < $times; $i++) {
         $conf->get('db.conn.host');
     }
     $endTime = microtime(true);
     $totalTime = round($endTime - $startTime, 6);
     $averageTime = round($totalTime / $times, 6);
     $memory_usage = memory_get_usage() - $base_memory_usage;
     $averageMemory = formatSize($memory_usage / $times);
     $memory_usage = formatSize($memory_usage);
     if (LOTUS_UNITTEST_DEBUG) {
         echo "\n----------------------config-----------------------------\n";
         echo "times      \t{$times}\n";
         echo "totalTime   \t{$totalTime}s\taverageTime   \t{$averageTime}s\n";
         echo "memoryUsage \t{$memory_usage}\taverageMemory \t{$averageMemory}";
         echo "\n---------------------------------------------------------\n";
     }
     $this->assertTrue(1 > $totalTime);
 }
 public function init()
 {
     $underMVC = false;
     if (isset($this->option["proj_dir"]) && !empty($this->option["proj_dir"])) {
         $this->proj_dir = rtrim($this->option["proj_dir"], '\\/') . '/';
         if (isset($this->option["app_name"]) && !empty($this->option["app_name"])) {
             $this->app_dir = $this->proj_dir . "app/" . $this->option["app_name"] . "/";
             $this->data_dir = $this->proj_dir . "data/" . $this->option["app_name"] . "/";
             $underMVC = true;
         } else {
             trigger_error("Lotus option [app_name] is missing.");
         }
     }
     /**
      * Load core component
      */
     require_once $this->lotusRuntimeDir . "Store.php";
     require_once $this->lotusRuntimeDir . "StoreMemory.php";
     require_once $this->lotusRuntimeDir . "StoreFile.php";
     if ($this->defaultStoreDir) {
         if ($defaultStoreDir = realpath($this->defaultStoreDir)) {
             LtStoreFile::$defaultStoreDir = $defaultStoreDir;
         } else {
             trigger_error("invalid [default store dir]: " . $this->defaultStoreDir);
         }
     }
     if (!$this->devMode) {
         /**
          * accelerate LtAutoloader, LtConfig
          */
         $this->coreCacheHandle = new LtStoreFile();
         $prefix = sprintf("%u", crc32(serialize($this->app_dir)));
         $this->coreCacheHandle->prefix = 'Lotus-' . $prefix;
         $this->coreCacheHandle->useSerialize = true;
         $this->coreCacheHandle->init();
     }
     /**
      * Init Autoloader, do this before init all other lotusphp component.
      */
     $this->prepareAutoloader();
     /**
      * init Config
      */
     $this->prepareConfig();
     /**
      * Run dispatcher when under MVC mode
      */
     if ($underMVC) {
         $this->runMVC();
     }
 }
示例#8
0
 /**
  * 设置默认存储目录
  * @param string $dir
  * @return boolean
  */
 public static function setDefaultStoreDir($dir = null)
 {
     if (null === $dir) {
         $dir = sys_get_temp_dir();
     }
     self::$defaultStoreDir = $dir;
     return true;
 }
 /**
  * 测试Value数据类型支持情况
  * @dataProvider testValueTypeDataProvider
  */
 public function testValueType($value, $excepted)
 {
     for ($i = 0;; $i++) {
         switch ($i % 10) {
             case "0":
                 $storeHandle = new LtStoreMemory();
                 break;
             case "1":
                 $storeHandle = new LtStoreFile();
                 break;
             default:
                 break 2;
         }
         $storeHandle->init();
         $key = uniqid();
         $storeHandle->del($key);
         $result = $storeHandle->add($key, $value);
         $this->assertEquals($excepted, $result);
         if ($result) {
             $this->assertEquals($storeHandle->get($key), $value);
         }
     }
 }