I used the following command to setup my cronjob:
sudo crontab -e -u www-data
and the actual cronjob:
*/5 * * * * /bin/sh /var/www/cron.sh >/dev/null 2>&1
I also have APC running on my site. APC CLI is on:
apc.enable_cli = 1
However, I am getting the following error. It feels like the cron may not be running with enough previlages. Should the cron be run as root? Sources advised me against this.
Cron error while executing rule_apply_all:
exception 'Zend_Cache_Exception' with message 'can't get apc memory size' in /var/www/lib/Zend/Cache.php:209
Stack trace:
#0 /var/www/lib/Zend/Cache/Backend/Apc.php(191): Zend_Cache::throwException('can't get apc m...')
#1 /var/www/lib/Zend/Cache/Backend/TwoLevels.php(518): Zend_Cache_Backend_Apc->getFillingPercentage()
#2 /var/www/lib/Zend/Cache/Backend/TwoLevels.php(192): Zend_Cache_Backend_TwoLevels->_getFastFillingPercentage('saving')
#3 /var/www/lib/Zend/Cache/Core.php(390): Zend_Cache_Backend_TwoLevels->save('1391196921', 'MAGE_AW_FUE_LOC...', Array, 1800)
#4 /var/www/lib/Varien/Cache/Core.php(76): Zend_Cache_Core->save('1391196921', 'AW_FUE_LOCK', Array, 1800, 8)
#5 /var/www/app/code/core/Mage/Core/Model/Cache.php(380): Varien_Cache_Core->save('1391196921', 'AW_FUE_LOCK', Array, 1800)
#6 /var/www/app/code/core/Mage/Core/Model/App.php(1147): Mage_Core_Model_Cache->save(1391196921, 'aw_fue_lock', Array, 1800)
#7 /var/www/app/code/local/AW/Followupemail/Model/Cron.php(98): Mage_Core_Model_App->saveCache(1391196921, 'aw_fue_lock', Array, 1800)
After a little bit of tracing, I ended up at the following:
public function getFillingPercentage()
{
$mem = apc_sma_info(true);
$memSize = $mem['num_seg'] * $mem['seg_size'];
$memAvailable= $mem['avail_mem'];
$memUsed = $memSize - $memAvailable;
if ($memSize == 0) {
Zend_Cache::throwException('can\'t get apc memory size');
}
if ($memUsed > $memSize) {
return 100;
}
return ((int) (100. * ($memUsed / $memSize)));
}
So it must mean $memSize == 0
however when I setup a test PHP script and evaluate $memSize
, it gives me the right value. So why would during a cronjob would this be different?
I have commented out in local.xml
the following cache node and the cronjob is running fine. It would be ideal to understand what the following node actually does. I take it that Zend looks at this config:
<cache>
<backend>apc</backend>
<prefix>MAGE_</prefix>
</cache>
Best Answer
If you enabled
<backend>apc</backend>
and your site worked fine butcron.sh
was not, it could mean that you have several php installations on your server.First of all run in console
which php
. This will give you the actual php that is used for running your cron php script.For example in my case I've got
/usr/bin/php
.Now run
/usr/bin/php -m | grep "apc"
to check if APC library is enabled. Next check/usr/bin/php -i | grep apc
to get APC config.Recommended values for Magento are
Hope this will help you.