Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 2.0 - Cake was unable to write to File cache

I'm using CakePHP 2.0 RC-1. After checking out the project from SVN, the application is starting to complain that it can't write cache files to the tmp/cache directory. Since this is local, I know the directory is writeable and I can CLEARLY see that the directories are even filled with files, so the error is a bit strange.

Here are some of the errors I've encountered:

_cake_core_ cache was unable to write 'cake_dev_nb' to File cache

fopen(c:\cake\app\tmp\cache\models\cake_model_default_media) [function.fopen]: failed to open stream: No error [CORE\Cake\Cache\Engine\FileEngine.php, line 127]

No error?! Wth?

Now, if I look in the FileEngine file, at line 127 it reads:

if (!$handle = fopen($this->_File->getPathName(), 'c')) {
            return false;
}

By replacing the "c" with "w", no error is encountered and everything works as it should. But, it should not be necessary to modify the core Cake libraries to work around this problem. Let me repeat that on my other computer this works as intended, without editing the core library. Both use the Windows OS and the read/write rights to the tmp/cache-folder is exactly the same.

Edit: Here's a site that experiences the error outputs I'm having locally

Example site found by Googling. Not my site: http://www.12h30.net/credit/

Any suggestions?

Update: Here is why: This is caused if you have a PHP-version that's too low, before 5.2.6, as outlined by "api55" in the comments. Thanks for the reply. Hope this helps you too.

like image 939
Coreus Avatar asked Sep 28 '11 14:09

Coreus


3 Answers

Well, in my case, when I checked my app, it hadn't the /tmp folder. Then I created the structure (/tmp/cache/models, /tmp/cache/persistent) and all worked well. This happened to me maybe git ignore empty folders, so they weren't created.

like image 163
Shad Avatar answered Oct 20 '22 14:10

Shad


I had a similar problem, it was because I had chown -R www to the app/tmp directory to get Cake to run "properly" without giving everyone write privileges. Looks like during development the only way to use the console and the web is to give everyone write privileges, or add yourself to the www group perhaps.

Easy solution:

chmod -R 777 app/tmp

or

chown -R username app/tmp

while using the console and

chown -R www app/tmp

when using the web

like image 39
Ian Will Avatar answered Oct 20 '22 12:10

Ian Will


Just give the right CHMOD (776 works fine for me) to app/tmp

like image 26
user982872 Avatar answered Oct 20 '22 14:10

user982872