CakePHP 2.0 - Cake was unable to write to File cache

Coreus picture Coreus · Sep 28, 2011 · Viewed 33.3k times · Source

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.

Answer

Shad picture Shad · Jul 5, 2012

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.