Intermittent hook_menu error - call_user_func_array() expects parameter 1 to be a valid callback As the title suggests I'm getting intermittent errors when hook_menu is called. Based on the error message it's as if the callback can not be found. Clearing the cache resolves the issue and the page works as expected. However, if the server is idle the error reappears. Any ideas as to what might be happening? Here are some details:

Error as reported in log:


  Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_protected_download' not found or invalid function name in menu_execute_active_handler() (line 517 of /var/www/drupal/includes/menu.inc).


All code is in the my_module.module and the module is enabled:

function my_module_menu()
{
    $items = array();
    $items['lesson-register-for-download'] = array(
        'path' =&gt; 'download/register',
        'title' =&gt; t('Register to Download a Lesson Plan'),
        'title callback' =&gt; FALSE,
        'access callback' =&gt; TRUE,
        'type' =&gt; MENU_CALLBACK,
        'page callback' =&gt; '_protected_download',
    );
    return $items;
}

function _protected_download()
{
    // check cookies and redirect here
}
You say your code is in my_module.inc, which means you have to tell the menu system that it is in there.

By default drupal will load my_module.module, but because the function is not in there it can't find the function.

As a side note, generally you should put hooks like hook_menu() in the .module file.

To tell the menu system that it has to load my_module.inc for your menu callback, do this:

$items['download/register'] = array(
  'title' =&gt; 'Register to Download a Lesson Plan',
  'access callback' =&gt; TRUE,
  'type' =&gt; MENU_CALLBACK,
  'page callback' =&gt; '_protected_download',
  'file' =&gt; 'my_module.inc',
);


Note the 'file' param.

Also, I made a couple of other changes:


Removed t() from the title and removed the 'title callback', because by default title callback is t().
Removed the 'path' param and changes the array key for the menu item. The path param was used in drupal 6 but not in drupal 7.