【问题标题】:PHP Fatal error: Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/tmp" must be a directory'PHP 致命错误:未捕获的异常 'Zend_Cache_Exception' 带有消息 'cache_dir "/tmp" must be a directory'
【发布时间】:2014-02-16 08:28:07
【问题描述】:

我有关于 zend cache_dir 的问题。 我尝试将我的站点从一台服务器转移到另一台服务器,并且它可以工作。 但是,当我尝试访问该站点时,它会显示此错误:

PHP Fatal error:  Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/tmp" must be a directory' in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php:209
Stack trace:

- #0 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(178): Zend_Cache::throwException('cache_dir "/tmp...')
- #1 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(129): Zend_Cache_Backend_File->setCacheDir('/tmp')
- #2 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
- #3 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
- #4 /home/aiesorgm/public_html/gcpi/application/Bootstrap.php(55): Zend_Cache::factory('Page', 'File', Array, Array)
- #5 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initCache()
- #6 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract-> in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php on line 209

我已经尝试了可以​​从 stackoverflow 获得的所有解决方案,但仍然无法正常工作。 我还在公共文件夹中创建了 tmp 目录并将权限更改为 777。

应用程序/Bootstrap.php

protected function _initCache() {
    $info = Zend_Registry::get('info');

    $backendOptions = array(
        'cache_dir' => sys_get_temp_dir(),
        'hashed_directory_level' => 1,
        'file_name_prefix' => 'style',
        'automatic_cleaning_factor' => 1
    );
    $frontendOptions = array(
        'lifetime' => $info['cache']['lifetime'],
        'automatic_serialization' => true,
        'caching' => ($info['cache']['enabled'] == '1') ? true : false,
    );
    $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
    Zend_Registry::set('cache', $cache);
}

/library/Zend/Cache/Backend/File.php

    protected $_options = array(
    'cache_dir' => null,
    'file_locking' => true,
    'read_control' => true,
    'read_control_type' => 'crc32',
    'hashed_directory_level' => 0,
    'hashed_directory_perm' => 0700,
    'file_name_prefix' => 'zend_cache',
    'cache_file_perm' => 0600,
    'metadatas_array_max_size' => 100
);

文件夹结构

应用

  • 配置
  • 控制器
  • 表格
  • 布局
  • 型号
  • 查看

文档

图书馆

公开

  • CSS
  • js
  • 图片
  • tmp
  • .htaccess
  • index.php

花 10Q 时间阅读这篇文章。

【问题讨论】:

    标签: php .htaccess twitter-bootstrap zend-framework caching


    【解决方案1】:

    /tmp 是完整路径,因此 ZF 不会尝试写入公共文件夹中名为 tmp 的文件夹,而是尝试写入文件系统根目录下的系统临时文件夹。

    我建议改为设置一个项目特定的缓存文件夹:

    $backendOptions = array(
        'cache_dir' => APPLICATION_PATH.'/../data/cache',
        'hashed_directory_level' => 1,
        'file_name_prefix' => 'style',
        'automatic_cleaning_factor' => 1
    );
    

    然后在您的项目中创建一个名为 data 的文件夹,并在其中创建一个 cache 文件夹,并使其可写。

    【讨论】:

    • 您好,蒂姆,感谢您的解决方案。它就像一个魅力。再次感谢:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2013-08-24
    • 2012-04-25
    • 2014-03-17
    相关资源
    最近更新 更多