问题
I've a CakePHP site which is throwing errors (it was fine at first, and has been online for several months - not sure when the problem started).
I'm getting:
Warning (512): _cake_core_ cache was unable to write 'cake_dev_en-us' to Apc cache [CORE/Cake/Cache/Cache.php, line 310] Warning (512): _cake_core_ cache was unable to write 'cake_en-us' to Apc cache [CORE/Cake/Cache/Cache.php, line 310] Warning (512): _cake_model_ cache was unable to write 'default_projects' to Apc cache
[CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_projects' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_clients' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_clients' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_projectpages' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_projectpages' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_settings' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
Warning (512): _cake_model_ cache was unable to write 'default_settings' to Apc cache [CORE/Cake/Cache/Cache.php, line 310]
I've made sure that the tmp directory is writeable (have set it and all contained folders and files to 0777; also checked that it did update properly, and it did); I've also switched off error reporting in core.php by setting the debug level to 0.
Most of the site is fine, but this particular page is pulled in by AJAX, and I don't know whether that's making any difference.
I've patched it by setting "display: none" on cake-error, but I need to understand why this is happening. Firstly, what's causing the error? And secondly, why is the core setting being ignored?
回答1:
I was getting this APC caching error when running a CakePHP site on Zend Server 7. Unfortunately Zend Server appears to ship with a fake/substitute APC layer, and from my tests the variable data-store doesn't work (the functions always return false) which is what CakePHP is complaining about.
This screen in the ZendServer dashboard shows APC.

The solution is to either:
Completely disable APC caching by editing
app/Config/core.php
to comment out the following lines.../*if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) { $engine = 'Apc'; }*/
OR, you can only load APC conditionally. In my case I just wanted to just disable it on my local development server but leave it active for production.
$isLocalDevelopment = strpos($_SERVER['SERVER_NAME'], '.dev'); if (!$isLocalDevelopment && extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) { $engine = 'Apc'; }
回答2:
I encountered this error sometimes, i think it was caused by APC running out of memory (caused by heavy load in application). Also misconfiguration of APC can be a cause of this.
http://php.net/manual/en/apc.configuration.php:
Once the server is running, the apc.php script that is bundled with the extension should be copied somewhere into the docroot and viewed with a browser as it provides a detailed analysis of the internal workings of APC. If GD is enabled in PHP, it will even display some interesting graphs. The first thing to ensure, of course, is that it is actually caching files. If APC is working, the Cache full count number (on the left) will display the number of times the cache has reached maximum capacity and has had to forcefully clean any entries that haven't been accessed in the last apc.ttl seconds. This number is minimized in a well-configured cache.
so i recommend to analyze output of apc.php (on ubuntu stored typicaly in /usr/share/doc/php-apc/) and as a first fix to increase size of memory segment allocated for APC.
in php.ini add line
apc.shm_size = 64M
(or whatever size appropriate, default is 32M)
回答3:
It is about the apache user write permission, on development mode when I usually do a
# chmod -R 777 app/tmp
but on production you must do the app/tmp directory writable for the apache web server user
Best Regards
回答4:
Change Group Owner in tmp folder for your app cache :
sudo chown -R User:_www /Applications/Site/app/tmp/
then make sure you have had set permissions enough 775
来源:https://stackoverflow.com/questions/12987434/getting-unable-to-write-errors-in-cakephp-site