Zend Framework : Could not determine temp directory, please specify a cache_dir manually
11,578
Solution 1
Well, it says
"Please specify a cache_dir manually"
So do that.
Example from Reference Guide:
$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);
Equivalent when using the Cache Resource Plugin:
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
Reference:
- http://framework.zend.com/manual/en/zend.cache.backends.html#zend.cache.backends.file
- http://framework.zend.com/manual/en/zend.cache.introduction.html
- http://zendframework.com/manual/en/zend.application.available-resources.html
Solution 2
Something like this should be helpful:
$_SERVER['TEMP'] = realpath(dirname(__FILE__) . '/tmp');
Solution 3
When looking at the Zend/Cache/Backend.php code, there are some alternatives to allow correct guessing of the cache_dir:
- Setting evironment variables like TMPDIR, TEMP or TMP
- set "upload_tmp_dir" in php.ini
- allow access to "/tmp" or "\temp"
At least that's how I read the code:
/**
* 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');
}
Solution 4
I was using 'memcached' instead of 'File', so my problem was a little bit different. I solved this by using:
$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);
Solution 5
I have created "tmp" folder in the main directory it worked for me
Author by
Future King
Updated on June 04, 2022Comments
-
Future King about 2 years
I am just learning Zend Framework. I created a simple Zend_Form and when I submitted the form I got following error:
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}
Request Parameters:
array ( 'controller' => 'bug', 'action' => 'submit', 'module' => 'default', 'author' => '7676', 'email' => '[email protected]', 'date' => '12/12/2010', 'url' => 'http://blogs.antarjaal.in/takneek/?p=1354', 'description' => 'tytytyty t', 'priority' => 'low', 'status' => 'new', 'submit' => 'Submit', )
System config:
- Windows 7
- IIS 7.5
- PHP 5.3
- Zend Framework 1.11.4
-
Future King about 13 yearsWhere should I write this code? is it possible to write this code in application.ini
-
Future King about 13 yearsIt looks like PHP is not able to read/write in C:\Windows\Temp directory. What permission do I have to set to C:\Windows\Temp
-
Future King about 13 yearsI didn't used cache. But I have created a model with extends from Zend_Db_Table_Abstract. I think that is using cache. because when I submit the form it calls the model and the error displays.
-
Tomáš Fejfar about 13 yearsCache is never created unless you do that explicitely. You may have put that into application.ini.
-
Tomáš Fejfar about 13 yearsAhw, it actually comes from Zend_Date. Check if you have not set Zend_Date to use cache. Doesn't seem much like ZF to force you to use cache.
-
Addshore about 8 yearsIt looks like PHP can write to that directory (try it out in PHP). It looks like is_writable() currently always returns false on the directory itself. You can however make a file in the directory using PHP, and when calling is_writable() on that file it will return true.
-
giovannipds over 7 yearsConfig codes didn't work to me, neither specifying the cache_dir directory, seems like it still bugs for whatever reason...
-
giovannipds over 7 yearsAnd the var
$cache
comes from where?