Menu access callback function called multiple times I have following menu defined with access callback function. As You can see this is a hack so I can use REST via GET ( normally Services do not offer this ).

All my endpoints are defined /rest/api/[endpoint] this is a /config one:

function MYMODULE_menu() {
    $menus['rest/api/config'] = array(
        'title' =&gt; 'Configuration',
        'page callback' =&gt; 'MYMODULE_config',
        'access callback' =&gt; 'MYMODULE_access_callback_basic_auth',
        'type' =&gt; MENU_CALLBACK,
    );
    return $menus;
}


The issue is that the MYMODULE_access_callback_basic_auth is called 5-times for every request.

Can You help me why this happens ?
Drupal forms are clever enough to know whether or not they've been submitted in the current page call and can react accordingly. Your best bet would be to move your code logic to inside the form function, where I think you can check for $form_state['#submitted'] to decide whether this code runs or not.

Alternatively you could check for the existence of $_POST variables in the MYMODULE_menu() function.


  Check and read it out $form_state['cache'] = true; from here.


Hope that helps.