Prechádzať zdrojové kódy

聊天demo数据文件存储位置

walkor 11 rokov pred
rodič
commit
81227e55f4

+ 1 - 1
applications/Demo/Config/Store.php

@@ -16,7 +16,7 @@ class Store
     public static $driver = self::DRIVER_FILE;
     
     // 如果使用文件存储,则在这里设置数据存储的目录,默认/tmp/下
-    public static $storePath = '/tmp/';
+    public static $storePath = '/tmp/workerman-Demo/';
     
     // 如果是memcache存储,则在这里设置memcache的ip端口,注意确保你安装了memcache扩展
     public static $gateway = array(

+ 5 - 2
applications/Demo/Lib/StoreDriver/File.php

@@ -30,6 +30,10 @@ class File
     public function __construct($config_name)
     {
         $this->dataFile = \Config\Store::$storePath . "/$config_name.store.cache.php";
+        if(!is_dir(\Config\Store::$storePath) && !mkdir(\Config\Store::$storePath, 0777, true))
+        {
+            throw new \Exception('cant not mkdir('.\Config\Store::$storePath.')');
+        }
         if(!is_file($this->dataFile))
         {
             touch($this->dataFile);
@@ -37,8 +41,7 @@ class File
         $this->dataFileHandle = fopen($this->dataFile, 'r+');
         if(!$this->dataFileHandle)
         {
-            $error_msg = "can not fopen($this->dataFile, 'r+')";
-            throw new \Exception($error_msg);
+            throw new \Exception("can not fopen($this->dataFile, 'r+')");
         }
     }