CakePHP 写入缓存时偶尔出现错误警告 [英] Ocasional error warning when CakePHP is writing to the cache

查看:29
本文介绍了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天全站免登陆