douhan5547 2013-01-09 15:48
浏览 91

Zend Cache异常:'cache_dir“/home/(...)/application/../data/tmp/”不可写'

I'm really new to Zend, few days of use.

I'm getting a fatal error message:

Fatal error:  Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/home/[REDACTED]/application/../data/tmp/" is not writable' in /home/[REDACTED]/library/Zend/Cache.php:209
Stack trace:
#0 /home/[REDACTED]/library/Zend/Cache/Backend/File.php(181): Zend_Cache::throwException('cache_dir "/hom...')
#1 /home/[REDACTED]/library/Zend/Cache/Backend/File.php(129): Zend_Cache_Backend_File->setCacheDir('/home/user/Proj...')
#2 /home/[REDACTED]/library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
#3 /home/[REDACTED]/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
#4 /home/[REDACTED]/application/Bootstrap.php(42): Zend_Cache::factory('Core', 'File', Array, Array)
#5 /home/[REDACTED]/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initCache()
#6 /home/[REDACTED]/library/Zend/Applica in /home/[REDACTED]/library/Zend/Cache.php on line 209

According to the error message, I would expect a folder permissions issue on the tmp directory. The directory is, however, writable:

user@[REDATCED]:~/[REDATCED]/data$ ls -hal
total 24K
drwxrwxr-x  6 user user 4,0K Jan  7 18:40 .
drwxr-xr-x 12 user user 4,0K Jan  9 12:50 ..
drwxrwxr-x  3 user user 4,0K Dez 17 11:42 locales
drwxrwxr-x  2 user user 4,0K Dez 17 11:42 logs
drwxrwxr-x  2 user user 4,0K Dez 17 11:42 sessions
drwxrwxr-x  2 user user 4,0K Jan  7 18:40 tmp

The workaround is to comment the following lines on application/Bootstrap.php:

    protected function _initCache() {
          $frontendOptions = array(
              'lifetime' => 7200, // cache lifetime of 2 hours
              'automatic_serialization' => true
          );

          $backendOptions = array(
              'cache_dir' => APPLICATION_PATH . '/../data/tmp/' // Directory where
          );

          // getting a Zend_Cache_Core object
          $this->cache = Zend_Cache::factory('Core', 'File',
            $frontendOptions, $backendOptions);

          Zend_Registry::set('cache', $this->cache);

          Zend_Date::setOptions(array(
              'cache' => $this->cache
          ));

This workaround was suggested by a coworker, I have no idea what I'm doing here or even if this code is part of Zend or our codebase. I don't like ugly hacks, or "fixing" stuff by commenting out code, or doing anything without knowing what I'm doing, or the reason behind it.

Besides, the code seems to be working on my coworkers' machines. And every time I pull their code commits from the repository I get an uncommented copy anyway.

I probably could exclude the file from the repository or anything like that (I'm new to git as well), but I really prefer:

  • Knowing the cause for the error
  • Knowing the solution
  • 写回答

3条回答 默认 最新

  • dpchen2004 2013-01-09 15:48
    关注

    As I was writing this question I noticed my mistake, the tmp directory is writable by myself and other users of the same group, apparently Zend will access the files as another user. The solution was to chmod 777 on the folder, making it writable.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行