I get this error :

cache_bootstrap(hook_info) was not cleared. APC cli uses a different memory storage then the webserver. For more info see: http://drupal.org/node/1278232 [warning]
WD php: Warning: Invalid argument supplied for foreach() in DrupalAPCCache->getMultiple() (line 175 of ***/sites/all/modules/contrib/apc/drupal_apc_cache.inc). [warning]
Warning : Invalid argument supplied for foreach() dans DrupalAPCCache->getMultiple() (ligne 175 dans ***/sites/all/modules/contrib/apc/drupal_apc_cache.inc). [error]
Command core-cron needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command.

=> just add a if($fetch) before the foreach in case of dummy apc_fetch

Files: 
CommentFileSizeAuthor
#4 apc-bug-1834228-4.patch582 bytesrudetrue

Comments

MrHaroldA’s picture

Can you give me some steps to reproduce this?

quazardous’s picture

it's just a clue : create a drush command that have to get items from cache...

<?php
function getMultiple(&$cids) {
...
   
$fetch = apc_fetch(array_keys($keys));
   
$cache = array();
    foreach (
$fetch as $key => $data) {
     
$cache[$keys[$key]] = $this->prepareItem($fetch[$key]);
    }
...
}
?>

since there is a dummy apc_fetch() in cli mode that returns FALSE (and apc_fetch() can return FALSE too) sometimes the foreach yields an error ...

I hope that helps :/

Jorrit’s picture

Same problem here, getMultiple() should check the return value of apc_fetch().

I changed the code to:

    $fetch = apc_fetch(array_keys($keys));
    $cache = array();
    if (!empty($fetch)) {
      foreach ($fetch as $key => $data) {
        $cache[$keys[$key]] = $this->prepareItem($fetch[$key]);
      }
    }
    unset($fetch);
rudetrue’s picture

Status:Active» Needs review
StatusFileSize
new582 bytes

To reproduce set "apc.enable_cli=0" in your php.ini/apc.ini and attempt to use drush. The command "drush status" will cause the warning to appear.

I created a patch file using the code from #2 and #3. This causes the warning to no longer appear.

Jorrit’s picture

Status:Needs review» Needs work

The patch works fine, but you are using four spaces to indent instead of two.

R.Muilwijk’s picture

What would the return value be of apc_fetch. The current check is !empty(). Shouldn't it be is_array()?

Jorrit’s picture

I guess that would also work. It either returns false or an array. Empty also checks for empty arrays and it is a fast function, so it will save you entering the foreach loop even when the result is an empty array.

R.Muilwijk’s picture

Status:Needs work» Fixed

Ok. Committed to dev.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.