【问题标题】:Zend Framework : Could not determine temp directory, please specify a cache_dir manuallyZend 框架:无法确定临时目录,请手动指定 cache_dir
【发布时间】:2011-08-04 19:25:15
【问题描述】:

我只是在学习 Zend 框架。我创建了一个简单的 Zend_Form,当我提交表单时出现以下错误:

An error occurred
Application error
Exception information:

Message: Could not determine temp directory, please specify a cache_dir manually
Stack trace:

 - 0 H:\Documents\IIS_Server_Root\zendframework\Zend\Cache\Backend.php(197): Zend_Cache::throwException('Could not deter...')
 - 1 H:\Documents\IIS_Server_Root\zendframework\Zend\Cache\Backend\File.php(123): Zend_Cache_Backend->getTmpDir()
 - 2 H:\Documents\IIS_Server_Root\zendframework\Zend\Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
 - 3 H:\Documents\IIS_Server_Root\zendframework\Zend\Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
 - 4 H:\Documents\IIS_Server_Root\zendframework\Zend\Locale\Data.php(314): Zend_Cache::factory('Core', 'File', Array, Array)
 - 5 H:\Documents\IIS_Server_Root\zendframework\Zend\Locale\Format.php(808): Zend_Locale_Data::getList('en_US', 'day')
 - 6 H:\Documents\IIS_Server_Root\zendframework\Zend\Locale\Format.php(1118): Zend_Locale_Format::_parseDate('12/12/2010', Array)
 - 7 H:\Documents\IIS_Server_Root\zendframework\Zend\Date.php(4765): Zend_Locale_Format::getDate('12/12/2010', Array)
 - 8 H:\Documents\IIS_Server_Root\zendframework\Zend\Validate\Date.php(175): Zend_Date::isDate('12/12/2010', 'MM-DD-YYYY', NULL)
 - 9 H:\Documents\IIS_Server_Root\zendframework\Zend\Form\Element.php(1395): Zend_Validate_Date->isValid('12/12/2010', Array)
 - 10 H:\Documents\IIS_Server_Root\zendframework\Zend\Form.php(2252): Zend_Form_Element->isValid('12/12/2010', Array)
 - 11 H:\Documents\IIS_Server_Root\localhost\zfprojects\zf_cms\application\controllers\BugController.php(30): Zend_Form->isValid(Array)
 - 12 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Action.php(513): BugController->submitAction()
 - 13 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('submitAction')
 - 14 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
 - 15 H:\Documents\IIS_Server_Root\zendframework\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
 - 16 H:\Documents\IIS_Server_Root\zendframework\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
 - 17 H:\Documents\IIS_Server_Root\localhost\zfprojects\zf_cms\public\index.php(26): Zend_Application->run()
 - 18 {main}  

请求参数:

array (
  'controller' => 'bug',
  'action' => 'submit',
  'module' => 'default',
  'author' => '7676',
  'email' => 'ankur_gupta555@yahoo.com',
  'date' => '12/12/2010',
  'url' => 'http://blogs.antarjaal.in/takneek/?p=1354',
  'description' => 'tytytyty t',
  'priority' => 'low',
  'status' => 'new',
  'submit' => 'Submit',
)  

系统配置:

  • Windows 7
  • IIS 7.5
  • PHP 5.3
  • Zend 框架 1.11.4

【问题讨论】:

  • 如果以下任何答案解决了您的问题,请通过勾选投票按钮下方的复选标记图标来接受它们。谢谢。

标签: php zend-framework caching frameworks


【解决方案1】:

我在它为我工作的主目录中创建了“tmp”文件夹

【讨论】:

    【解决方案2】:

    嗯,它说

    "Please specify a cache_dir manually"
    

    那就这样吧。

    参考指南中的示例:

    $frontendOptions = array(
       'lifetime' => 7200, // cache lifetime of 2 hours
       'automatic_serialization' => true
    );
    
    $backendOptions = array(
        'cache_dir' => '/path/to/cache' // Directory where to put the cache files
    );
    
    // getting a Zend_Cache_Core object
    $cache = Zend_Cache::factory('Core',
                                 'File',
                                 $frontendOptions,
                                 $backendOptions);
    

    使用缓存资源插件时等效:

    resources.cachemanager.database.frontend.name = Core
    resources.cachemanager.database.frontend.customFrontendNaming = false
    resources.cachemanager.database.frontend.options.lifetime = 7200
    resources.cachemanager.database.frontend.options.automatic_serialization = true
    
    resources.cachemanager.database.backend.name = File
    resources.cachemanager.database.backend.customBackendNaming = false
    resources.cachemanager.database.backend.options.cache_dir = "/path/to/cache"
    resources.cachemanager.database.frontendBackendAutoload = false
    

    参考:

    【讨论】:

    • 我应该在哪里写这段代码?是否可以在 application.ini 中编写此代码
    • 看起来 PHP 无法在 C:\Windows\Temp 目录中读取/写入。我必须将什么权限设置为 C:\Windows\Temp
    • 看起来 PHP 可以写入该目录(在 PHP 中尝试)。看起来 is_writable() 当前总是在目录本身上返回 false。但是,您可以使用 PHP 在目录中创建一个文件,当对该文件调用 is_writable() 时,它将返回 true。
    • 配置代码对我不起作用,也没有指定 cache_dir 目录,似乎无论出于何种原因它仍然存在错误......
    【解决方案3】:

    我认为这解决了问题,它为我解决了问题

    Zend_Date::setOptions(array('cache' => $cache)); // Active aussi pour Zend_Locale
    Zend_Translate::setCache($cache);
    

    在 bootstrap.php 中设置缓存后添加它

    【讨论】:

    • 而 var $cache 来自哪里?
    【解决方案4】:

    你可以输入.htaccess

    SetEnv TEMP /tmp
    

    【讨论】:

      【解决方案5】:

      我使用的是“memcached”而不是“文件”,所以我的问题有点不同。我通过使用解决了这个问题:

              $registry = Zend_Registry::getInstance ();
              $frontendOptions =
              array (
                  'lifetime' => APPLICATION_ENV == 'development' ? '10' : '3600', 
                  'automatic_serialization' => true
              );
      
      
          $backendOptions = array(
                              'servers' => array( array(
                                  'host' => APPLICATION_ENV == 'development' ? '***' : '***', 
                                  'port' => '***'
                              ) ),
                              'compression' => true
          );
      
          $cache = Zend_Cache::factory ( 'Core', 'Memcached', $frontendOptions, $backendOptions );
      
      // Below is the fix for the problem! It appears that some validators / translates are caching
      Zend_Locale::setCache($cache);
      Zend_Translate::setCache($cache);
      

      【讨论】:

        【解决方案6】:

        这样的事情应该会有所帮助:

        $_SERVER['TEMP'] =  realpath(dirname(__FILE__) . '/tmp');
        

        【讨论】:

          【解决方案7】:

          查看 Zend/Cache/Backend.php 代码时,有一些替代方法可以正确猜测 cache_dir:

          • 设置环境变量,例如 TMPDIR、TEMP 或 TMP
          • 在 php.ini 中设置“upload_tmp_dir”
          • 允许访问“/tmp”或“\temp”

          至少我是这样阅读代码的:

          /**
           * Determine system TMP directory and detect if we have read access
           *
           * inspired from Zend_File_Transfer_Adapter_Abstract
           *
           * @return string
           * @throws Zend_Cache_Exception if unable to determine directory
           */
          public function getTmpDir()
          {
              $tmpdir = array();
              foreach (array($_ENV, $_SERVER) as $tab) {
                  foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
                      if (isset($tab[$key])) {
                          if (($key == 'windir') or ($key == 'SystemRoot')) {
                              $dir = realpath($tab[$key] . '\\temp');
                          } else {
                              $dir = realpath($tab[$key]);
                          }
                          if ($this->_isGoodTmpDir($dir)) {
                              return $dir;
                          }
                      }
                  }
              }
              $upload = ini_get('upload_tmp_dir');
              if ($upload) {
                  $dir = realpath($upload);
                  if ($this->_isGoodTmpDir($dir)) {
                      return $dir;
                  }
              }
              if (function_exists('sys_get_temp_dir')) {
                  $dir = sys_get_temp_dir();
                  if ($this->_isGoodTmpDir($dir)) {
                      return $dir;
                  }
              }
              // Attemp to detect by creating a temporary file
              $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
              if ($tempFile) {
                  $dir = realpath(dirname($tempFile));
                  unlink($tempFile);
                  if ($this->_isGoodTmpDir($dir)) {
                      return $dir;
                  }
              }
              if ($this->_isGoodTmpDir('/tmp')) {
                  return '/tmp';
              }
              if ($this->_isGoodTmpDir('\\temp')) {
                  return '\\temp';
              }
              Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
          }
          

          【讨论】:

            【解决方案8】:

            关闭/禁用缓存 :) 为什么在学习时将它用于简单的应用程序?还有更重要的东西要学;)

            【讨论】:

            • 我没有使用缓存。但是我创建了一个从 Zend_Db_Table_Abstract 扩展的模型。我认为这是使用缓存。因为当我提交表单时,它会调用模型并显示错误。
            • 永远不会创建缓存,除非您明确地这样做。您可能已将其放入 application.ini。
            • 啊,它实际上来自 Zend_Date。检查你是否没有设置 Zend_Date 使用缓存。看起来不像 ZF 强迫你使用缓存。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-06-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-01-21
            • 2012-01-18
            • 1970-01-01
            相关资源
            最近更新 更多