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:

  • 1
    Have you tested to see if you run into the same issue with apc.enable_cli = 0?
    – davidalger
    Commented Feb 1, 2014 at 0:30
  • @davidalger no I haven't tried that actually. All the sources told me to set the value as 1 however. I've turned off APC for now by commenting out the nodes in local.xml. Commented Feb 1, 2014 at 4:31
  • 1
    I recommend you to debug your cron job script. Log the output of ini_get for apc.enabled, apc.shm_size, apc.num_files_hint, apc.user_entries_hint, apc.max_file_size, apc.stat, apc.optimization, apc.shm_segments, apc.enable_cli, apc.cache_by_default, apc.include_once_override Commented Feb 3, 2014 at 8:28

6 Answers 6


If you enabled <backend>apc</backend> and your site worked fine but cron.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.

  • I am actually using the exact same settings. Commented Feb 3, 2014 at 12:36
  • Have you run the commands which I described in my answer? Are you sure that cron.sh uses the correct php instance? Commented Feb 3, 2014 at 14:51

Francis, i did some research on your problem and two solution came across: apc.enable_cli=1 and apc prefix_for_store_ in local.xml. You may need to restart Apache/Nginx after you change any APC config. Check the recipes in these articles (if you haven't already): http://www.magentocommerce.com/boards/viewthread/180339/, http://www.magentodeveloperleedsuk.co.uk/zend_cache_exception-cant-get-apc-memory-size/, http://phpbugs.wordpress.com/2012/11/03/magento-exception-zend_cache_exception-with-message-cant-get-apc-memory-size/, http://www.magecorner.com/magento-apc-cache/, http://www.qicai.us/solved-uncaught-exception-zend_cache_exception-with-message-cant-get-apc-memory-size, http://www.creation-site-lyon.com/2010/10/28/magento-cron-et-apc/(this one is in french, but you can translate it using Google).


To answer your question, no you should not need to run cron.sh as root. I cannot answer why your site works fine with APC enabled but cron.sh does not. I would recommend creating a debug script /var/www/debug.php and copy the lines from getFillingPercentage() into it:

$mem = apc_sma_info(true);
$memSize    = $mem['num_seg'] * $mem['seg_size'];
$memAvailable= $mem['avail_mem'];
$memUsed = $memSize - $memAvailable;

var_dump($mem, $memSize, $memAvailable, $memUsed);

Run this command using almost the same line as your original cron.sh, but with 3 important changes:

MAILTO="[email protected]"  # <-- Obvi this should be a real email address. #
*/5 * * * * /bin/sh /var/www/cron.sh /var/www/debug.php 2>&1
  1. Your debug script is the first argument to cron.sh. This will be run instead of cron.php
  2. Add a MAILTO line for receiving cron output (useful for debugging)
  3. Do not pipe output to /dev/null, so the cron emails get sent (they are not sent if there is no output)
  • I tried the first half of what you are suggesting but you make an important point in the second half, thanks! Commented Feb 4, 2014 at 1:05
  • @FrancisKim Did you get any useful information from the debug script or the cron email output?
    – nachito
    Commented Feb 5, 2014 at 14:27

The apc.enable_cli = 1 wasn't being read from my /etc/php5/fpm/php.ini or /etc/php5/fpm/php.ini. Instead in /etc/php5/cli/conf.d/20-apcu.ini I inserted the 2 last lines:

apc.enabled = 1
apc.enable_cli = 1

This solved the issue. This command php -i | grep 'apc' helped me realise apc.enable_cli was indeed off contrary to what I thought.

  • 1
    The funny thing is that I advised you to run php -i | grep 'apc' command in my answer. Commented Feb 16, 2014 at 15:42

First if you have APC defined as a backend cache type or session storage in local.xml. don't. APC will be able to do what it needs without details from Magento. The cache type is known to be problematic (at least from my use). APC will cache generated OpCode from existing php/web server runtimes and cache them regardless of Magento's local.xml definition or not.

Second, try php -f /full/path/to/magento/cron.php and bypass the bash cron.sh, if you see exceptions being thrown after executing. I normally copy the crontab entry verbatim into the shell to make sure its firing off.

However, I would suspect simply removing


from local.xml and/or using something like Redds or Memcache instead would be better.

Utilize apc.php to validate the APC cache will still function without the entry if you like as well.

  • I had the APC activated and it worked like a charm...until it ended up in total super high loads from time to time. I still don't know why, but since I removed the APC out of the local.xml it worked as good as before. Though APC is actiavted (also in the CLI). What exactly does this setting in the local.xml? Commented Jan 23, 2015 at 10:41

I had the same problem. My provider told me, the cron.sh would try to change rights of apc it is not allowed to. So I removed the commands and the apc is fine as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.