CakePHP正在写入高速缓存时发生意外错误警告 [英] Ocasional error warning when CakePHP is writing to the cache

查看:261
本文介绍了CakePHP正在写入高速缓存时发生意外错误警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MAMP在本地开发CakePHP 2.2网站。经常,我得到一个或多个类似的警告,无法写入一个或多个缓存文件:

I'm developing a CakePHP 2.2 site locally with MAMP. Every so often, I get one or more warnings similar to this, about not being able to write to one or more cache files:

Warning: SplFileInfo::openFile(/Applications/MAMP/htdocs/mywebsite/www/app/tmp/cache/persistent/myapp_cake_core_cake_console_en-au): failed to open stream: Permission denied in /Applications/MAMP/htdocs/mywebsite/www/lib/Cake/Cache/Engine/FileEngine.php on line 313

奇怪的是, tmp是777,tmp / cache是​​777,而tmp / cache / persistent是777(不要担心...它不会是服务器上的777)。文件本身里面的tmp / cache / persistent是644 - 但我认为Cake是创建和管理该文件,并用所需的权限。

The weird thing is, /tmp is 777, tmp/cache is 777, and tmp/cache/persistent is 777 (don't worry... it won't be 777 on the server!). The file itself inside tmp/cache/persistent is 644 - but I assume Cake is creating and managing that file, and does so with the permissions it needs.

如果我只是刷新页面,错误消失(然后重新出现一段时间后)。我不做任何明确的缓存,所以这东西只是Cake做任何它自动做的。

If I just refresh the page, the error goes away (and then re-appears sometime later). I'm not doing any explicit caching, so this stuff is just Cake doing whatever it automatically does.

所以我的问题是:

a)Cake的这种自动缓存如何工作?它是否试图在每个页面刷新时写入该文件,并且仅在一段时间内失败一次?或者它只是试图在一段时间内写入该文件,但每次尝试失败?

a) How does this automatic caching of Cake's work? Is it trying to write to that file on every page refresh, and failing only once in a while? Or is it only trying to write to that file once in a while, but failing every time it tries?

b)如果它只是故障只有一次,我安全地忽略它?

b) If it's only failing only once in a while, can I safely just ignore it? And if it's failing every time it tries, how can I fix it?

预先感谢任何帮助!

推荐答案

这可能发生在不同于Apache的进程在缓存中创建文件时。例如,当您运行shell命令时,您可能会以不同于apache的用户身份执行此操作。

This happens probably when a process different from Apache create files in the cache. This can be the case for instance when you run shell commands as you probably do it as a different user than apache.

默认情况下,文件高速缓存将创建文件,创建修改它们的文件的用户,但这可以通过在core.php中的缓存配置中设置一个掩码来修复:

By default the File cache creates files with permissions allowing only the user that has created the files to modify them, but this can be fixed by setting a mask in the Cache config in core.php:

Cache::config('_cake_core_', array(
    'engine' => $engine,
    'prefix' => 'cake_core_',
    'path' => CACHE . 'persistent' . DS,
    'serialize' => ($engine === 'File'),
    'duration' => $duration,
    'mask' => 0666
));

Cache::config('_cake_model_', array(
    'engine' => $engine,
    'prefix' => 'cake_model_',
    'path' => CACHE . 'models' . DS,
    'serialize' => ($engine === 'File'),
    'duration' => $duration,
    'mask' => 0666
));

这篇关于CakePHP正在写入高速缓存时发生意外错误警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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