【问题标题】:CakePHP 2.x warning SplFileInfo due to cakeshell由于 cakeshell,CakePHP 2.x 警告 SplFileInfo
【发布时间】:2014-06-08 16:52:34
【问题描述】:

我编写了一个 cakeshell 脚本,我打算使用 cronjob 来使用它。在手动运行时(在测试期间),有时我的网站会抛出 SplFileInfo 警告,例如:

Warning: SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_file_map): 
failed to open stream: Permission denied in /var/www/flat/lib/Cake/Cache/Engine/FileEngine.php on line 313

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list): 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]: 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): _cake_model_ cache was unable to write 'default_flat_list' to File cache [CORE/Cake/Cache/Cache.php, line 309]

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]: 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]: 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]: 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]: 
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]

Warning (512): _cake_model_ cache was unable to write 'default_flat_list' to File cache [CORE/Cake/Cache/Cache.php, line 309]

发生了什么?以及如何解决这个问题?

如果我检查缓存上的 tmp 目录并持久化,则某些文件处于 root 权限下。是这个原因吗?

[root@Apps103 persistent]# ls
total 40K
-rw-rw-r-- 1 apache   43 Apr 22 17:49 myapp_cake_core_cake_
-rw-rw-r-- 1 root     43 Apr 23 10:01 myapp_cake_core_cake_console_
-rw-rw-r-- 1 root     43 Apr 23 10:01 myapp_cake_core_cake_dev_
-rw-rw-r-- 1 apache   43 Apr 23 10:26 myapp_cake_core_cake_dev_en-us
-rw-rw-r-- 1 apache   43 Apr 23 10:26 myapp_cake_core_cake_en-us
-rw-rw-r-- 1 apache   43 Apr 23 10:26 myapp_cake_core_default_en-us
-rw-rw-r-- 1 root   4.3K Apr 23 10:01 myapp_cake_core_file_map
-rw-rw-r-- 1 root   4.3K Apr 23 10:01 myapp_cake_core_method_cache

我尝试了这个链接SplFileInfo::openFile(/app/tmp/cache/persistent/cake_core_cake_console_):failed to open stream:Permission denied in /lib/.../FileEngine.php line 293的解决方案

我把它放在引导程序中

Cache::config('default', array(
    'engine' => 'File',
    'mask' => 0666,
));

// short  
Cache::config('short', array(
    'engine' => 'File',
    'duration' => '+1 hours',
    'path' => CACHE,
    'prefix' => 'cake_short_'
));

// long
Cache::config('long', array(
    'engine' => 'File',
    'duration' => '+1 week',
    'probability' => 100,
    'path' => CACHE . 'long' . DS,
));

但它不起作用。通常我会清理整个 tmp 目录以删除警告。然后它会再次正常工作。我不知道为什么,但是如果我运行 shell,直到第二天才会显示警告错误。 我的 tmp 目录(flat/app/tmp)在 apache 权限下。

【问题讨论】:

  • 我猜您需要确保 tmp 目录中的所有内容都是可写的。
  • @Kai 你是什么意思?我的 tmp 目录在 apache 权限下
  • this other answer 对您的问题有帮助吗?

标签: php shell cakephp cakephp-2.0 command-line-interface


【解决方案1】:

发生了什么?

tmp 文件夹通常位于应用程序目录中,并为所有请求共享,无论来源如何。一个相对常见的问题是通过 Web 请求创建的 tmp 文件对于控制台任务是只读的,反之亦然。

如果您以 root 身份运行 cli 任务,则 tmp 文件将使用所有者 root 创建 - 此后 webrequest(由 apache 运行)可能会尝试从 tmp 目录中删除或写入,但无法修改现有的 tmp 文件夹文件内容归根用户所有。

如何解决这个问题?

让 cli 和 web 请求使用 不同的 tmp 目录 - 或者只是确保 cli 和 web 用户都具有对 tmp 目录的写入权限。

这意味着将 TMP 常量 before CakePHP does 定义到 app/tmp 以外的位置,例如在cake.php:

...
$ds = DIRECTORY_SEPARATOR;
define('TMP', '/tmp/myapp');
...

或者确保 tmp 文件夹对两个用户都是可写的,例如:

cd app
chmod -R 777 tmp

【讨论】:

    猜你喜欢
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 2012-09-28
    相关资源
    最近更新 更多