CakePHP 2.x警告SplFileInfo由于蛋糕 [英] CakePHP 2.x warning SplFileInfo due to cakeshell

查看:136
本文介绍了CakePHP 2.x警告SplFileInfo由于蛋糕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个cakeshell脚本,我计划使用它使用cronjob。 (测试期间),有时我的网站将抛出SplFileInfo警告,例如:

I wrote a cakeshell script which I plan to use it using cronjob. while having run it manually (during testing), sometimes my site will throw SplFileInfo Warning e.g:

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]

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

What happened? and how to fix this?

如果我检查缓存上的tmp目录和持久化某些文件是根权限。这是原因吗?

If I check the tmp directory on cache and persistent some of the file are under root permissions. Is this the cause?

[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 _):无法打开流:Permission denied in /lib/.../FileEngine.php line 293

I将此引导到引导

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权限下。

but it does not work. Usually I clean up the whole tmp directory to remove the warning. then it will work fine again. I'm not sure why, but if I ran the shell, the warning error does not show, until the next day. My tmp directory (flat/app/tmp) is under apache permission.

推荐答案

发生了什么? >

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

What happened?

The tmp folder is normally in the app dir and shared for all requests no matter the origin. A relatively common problem is for tmp files created via a web request to be read-only for console tasks and vice-versa.

如果以root身份运行cli任务,将使用所有者root创建tmp文件 - 此后,webrequest(由apache运行)可能会尝试从其中删除或写入

If you run cli tasks as root, the tmp files will be created with the owner root - thereafter a webrequest (running by apache) may try to delete from or write to the tmp directory but be unable to modify the existing tmp folder contents as the files are owned by root.

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

Either make cli and web requests use different tmp directories - or simply ensure that both cli and web users have write permissions to the tmp directory.

这意味着定义TMP常量在CakePHP之前到除app / tmp之外的地方,例如在 cake.php 中:

That means either defining the TMP constant before CakePHP does to a place other than app/tmp, e.g. in cake.php:

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

或确保tmp文件夹对两个用户都可写,例如: / p>

Or ensure the tmp folder is writable to both users, e.g.:

cd app
chmod -R 777 tmp

这篇关于CakePHP 2.x警告SplFileInfo由于蛋糕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆