Vinai/Symlink-Cache

Running Cron Job from outside Magento root

danmshields opened this issue · 6 comments

I know that there was a patch for /app/code/community/Netzarbeiter/Cache/Model/Symlink.php however I feel as if there is still a bug here where if you have a cron job for cron.php or other cron jobs and it is running from outside the Magento root, you get the error

PHP Fatal error: Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir must be a directory' in /path/to/site/www/lib/Zend/Cache.php:209
Stack trace:
#0 /path/to/site/www/lib/Zend/Cache/Backend/File.php(154): Zend_Cache::throwException('cache_dir must ...')
#1 /path/to/site/www/lib/Zend/Cache/Backend/File.php(121): Zend_Cache_Backend_File->setCacheDir('var/cache')
#2 /path/to/site/www/app/code/community/Netzarbeiter/Cache/Model/Symlink.php(45): Zend_Cache_Backend_File->__construct(Array)
#3 /path/to/site/www/lib/Zend/Cache.php(153): Netzarbeiter_Cache_Model_Symlink->__construct(Array)
#4 /path/to/site/www/lib/Zend/Cache.php(94): Zend_Cache::_makeBackend('Netzarbeiter_Ca...', Array, true, true)
#5 /path/to/site/www/app/code/local/Mage/Core/Model/Cache.php(123): Zend_Cache::factory('Varien_Cache_Co...', 'Netzarbeiter_Ca...', Array, Array, true, true, true)
#6 /path/to/site/www/app/code/core/Mage/Core/Model/Config.php(1206): Mage_Core_Model_Cache->__const in /path/to/site/www/lib/Zend/Cache.php on line 209

I found that you are forced to set an absolute path in the local.xml for cache_dir, this is due to is_dir looking for the current working directory.

I don't know if this is a bug and happens as intended but should probably be called out to people that if you plan on running cron jobs that don't cd into the Magento root, use an absolute path.

Hi Dan,

thanks for your feedback. This commit should have taken care of that issue: 718cd58

Are you using the latest version?
If so and the issue persists, please reopen this issue.
Thank you.

I think it is still an issue, $this->_options['cache_dir'] is null but $options['cache_dir'] is not, so when doing this from a cron job initiated outside the Magento root var/cache is used and it can't find it in the working directory.

To reproduce, just make sure in the local.xml its set to var/cache and then from outside the magento root run php /path/to/cron.php

I don't have the ability to open the issue back up

Hi Dan,
of course, you are right. Thanks for the pointer.
I committed the patch just now: bf1945c
It seems to work for me with a quick test. Can you confirm that?

why do you have DS . $options['cache_dir']; when Mage::getBaseDir('cache') will already get you to var/cache? On mine the url is now site.com/var/cache/var/cache. Should it just be Mage::getBaseDir() . DS . $options['cache_dir'];

Because the cache_dir could be set to point somewhere else in the backend options.

Oh, right - now I get it.
Yes, taht was a bug. Thank you and sorry. I already hat fixed that in a second commit, too :)