【问题标题】:Message: cache_dir must be a directory消息:cache_dir 必须是一个目录
【发布时间】:2013-04-08 12:40:33
【问题描述】:

大家好,我对 Zend Framework 有一些问题。
我首先收到以下消息: 消息:
无法确定临时目录,请手动指定 cache_dir。
我搜索了谷歌并找到了这篇文章:Zend Framework : Could not determine temp directory, please specify a cache_dir manually
我读了它,现在当我填写表格时,我收到以下错误:
(我在错误中放置 .. 的任何地方都表示域。)

消息:cache_dir 必须是目录

- #0 /home/daan/domains/../library/Zend/Cache/Backend/File.php(154): Zend_Cache::throwException('cache_dir must ...')
 - #1 /home/daan/domains/../library/Zend/Cache/Backend/File.php(121): Zend_Cache_Backend_File->setCacheDir('/domains/daan.h...')
 - #2 /home/daan/domains/../library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
 - #3 /home/daan/domains/../library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
 - #4 /home/daan/domains/../library/Zend/Locale/Data.php(307): Zend_Cache::factory('Core', 'File', Array, Array)
 - #5 /home/daan/domains/../library/Zend/Locale/Format.php(796): Zend_Locale_Data::getList('nl_NL', 'day')
 - #6 /home/daan/domains/../library/Zend/Locale/Format.php(1106): Zend_Locale_Format::_parseDate('16-02-2013', Array)
 - #7 /home/daan/domains/../library/Zend/Date.php(4763): Zend_Locale_Format::getDate('16-02-2013', Array)
 - #8 /home/daan/domains/../library/Zend/Validate/Date.php(175): Zend_Date::isDate('16-02-2013', 'MM-DD-YYYY', NULL)
 - #9 /home/daan/domains/../library/Zend/Form/Element.php(1391): Zend_Validate_Date->isValid('16-02-2013', Array)
 - #10 /home/daan/domains/../library/Zend/Form.php(2135): Zend_Form_Element->isValid('16-02-2013', Array)
 - #11/home/daan/domains/../application/controllers/BugController.php(27): Zend_Form->isValid(Array)
 - #12 /home/daan/domains/../library/Zend/Controller/Action.php(513): BugController->submitAction()
 - #13 /home/daan/domains/../library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('submitAction')
 - #14 /home/daan/domains/../library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
 - #15 /home/daan/domains/../library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
 - #16 /home/daan/domains/../library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
 - #17 /home/daan/domains/../public_html/index.php(26): Zend_Application->run()
 - #18 {main} 

应用程序.ini:

resources.cachemanager.configFiles.frontend.name = File
resources.cachemanager.configFiles.frontend.customFrontendNaming = false
resources.cachemanager.configFiles.frontend.options.lifetime = false
resources.cachemanager.configFiles.frontend.options.automatic_serialization = true    
resources.cachemanager.configFiles.backend.name = File
resources.cachemanager.configFiles.backend.customBackendNaming = false
resources.cachemanager.configFiles.backend.options.cache_dir = APPLICATION_PATH      "/../tmp"
resources.cachemanager.configFiles.frontendBackendAutoload = false

初始化缓存:

 protected function _initCaching() {
$frontend = array(
'lifetime' => $time,
'automatic_serialization' => true
);
$backend = array(
'cache_dir' => sys_get_temp_dir(),
);
$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
Zend_Registry::set('cache', $cache);

}

文件夹结构:
.htpasswd
应用
awstats
图书馆
日志
public_ftp
public_html
时间

【问题讨论】:

  • 请编辑您的问题以包含您的缓存配置
  • @TimFountain 我不明白你的问题你的意思是我的 application.ini 我正在关注一本书,我是 Zend 的新手
  • 是的,application.ini 中与缓存相关的部分。或者,如果你的引导类中有一个 _initCache() 函数,那就是。
  • @TimFountain 我更新了我的问题
  • 您的应用程序中有“tmp”文件夹吗?您希望将缓存文件写入哪里?

标签: php zend-framework frameworks


【解决方案1】:

cache_dir 必须是目录:

当您将代码移动到另一台主机或服务器时,通常会出现此问题。这个问题主要有两种解决方案

1 - 确保你的缓存目录是可写的,或者你可以使 magento 的 var 文件夹可写

但有时这种情况不起作用,所以这里是替代解决方案。转到这个位置 lib/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_umask' => 0700,
        'file_name_prefix' => 'zend_cache',
        'cache_file_umask' => 0600,
        'metadatas_array_max_size' => 100
    );

如下更改此代码

protected $_options = array(
        'cache_dir' => '/var/www/html/webkul/magento/tmp',
        'file_locking' => true,
        'read_control' => true,
        'read_control_type' => 'crc32',
        'hashed_directory_level' => 0,
        'hashed_directory_umask' => 0700,
        'file_name_prefix' => 'zend_cache',
        'cache_file_umask' => 0600,
        'metadatas_array_max_size' => 100
    );

根据您的配置分配 cache_dir 的路径。

【讨论】:

  • 'cache_dir' => 路径是你的服务器路径,你需要根据你的服务器路径修改它你检查了吗?
【解决方案2】:

可能是 Zend 无法找到您的缓存目录。尝试像这样在 Bootstrap.php 中设置这个

protected function _initCache() {
    $frontend = array(
        'lifetime' => $time,
        'automatic_serialization' => true
    );
    $backend = array(
        'cache_dir' => sys_get_temp_dir(), /**automatically detects**/
    );
    $cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
    Zend_Registry::set('cache', $cache);
}

【讨论】:

  • 这不起作用@chandresh_cool。我现在什至无法打开表单我收到此错误:致命错误:未捕获的异常 'Zend_Cache_Exception' 带有消息 'cache_dir must be a directory' in 即使我将其更改为 777
【解决方案3】:

从您的引导程序中删除 _initCaching 函数,您不应该拥有这个和 application.ini 条目,因为它们都试图设置相同的东西(但使用不同的缓存位置)。

您的缓存目录设置为APPLICATION_PATH "/../tmp" - 即应用程序根目录中名为“tmp”的文件夹(不在应用程序文件夹中)。您是否 100% 确定您的 tmp 文件夹存在于该位置?如果是这样,您可以尝试更改 application.ini 配置以使用完整路径:

resources.cachemanager.configFiles.backend.options.cache_dir = "/home/daan/domains/whatever/tmp"

只是看看这是否能解决问题。

如果您仍然无法正常工作,请发布有关您的应用程序文件结构的更多信息。

【讨论】:

    【解决方案4】:

    这个问题的答案是打开 File.php 文件并更改 tmp 文件夹的路径。 当您将站点从一台服务器转移到另一台服务器时,通常会出现此问题。当您转移站点时,tmp 文件夹的路径不会更改为新的。所以编辑file.php并更改tmp文件夹的路径。

    【讨论】:

      【解决方案5】:

      magento root

      在 magento 目录中创建“tmp”文件为我解决了这个错误。 我能够轻松访问管理员

      【讨论】:

        【解决方案6】:

        为您的缓存目录分配完整路径。例如,

        'cache_dir' => '/var/www/html/var/cache1',
        

        【讨论】:

          【解决方案7】:

          更改/install/config/ 中的路径,编辑文件vfs.php 并输入新路径名。

          【讨论】:

            【解决方案8】:

            在 CentOS/RedHat 中出现此问题的原因之一可能是 Selinux。 我通过禁用 Selinux 解决了这个问题

            编辑/etc/selinux/config 文件并将SELINUX 设置为disabled。

            【讨论】:

              猜你喜欢
              • 2012-01-31
              • 2021-11-03
              • 1970-01-01
              • 2015-10-07
              • 2015-08-07
              • 1970-01-01
              • 2017-06-06
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多