Does Drupal parse (and/or run) hooks that are unrelated to the content being loaded by the current user?
For example, say I had a module foo installed and active with the following hooks:
<?php
// .. stuff ...
function foo_menu() {
$items = array();
$items['foo/show'] = array(
'title' => t('Foo!'),
'page callback' => 'foo_display_all',
'description' => 'All our foo are belong to you',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function foo_display_all() {
// About 100 lines of code
}
// ... stuff ...
Would Drupal parse (and thus effect the load time) for pages that aren’t listed in foo_menu? Put another way, would the length and complexity of foo_display_all effect how http://www.example.com/bar loads?
At risk of having two different questions here, I’ll say I would be grateful for an explanation (or link to an explanation) of how and why Drupal does or does not parse, rather than a yes/no answer.
hook_menu is used to tell drupal about what to do at specific urls, so the result of that is cached.
Drupal will only execute the content of the hooks themselves not the entire content of the file they are located in. So when hook menu is invoked in the above example, on the foo_menu() function will be run.
You can take a look at the intro text at the Hooks API
Edit:
In order for PHP to execute the function, it needs to include the file where it is located. So when Drupal wants to execute a hook, PHP would need to parse the code in that file. That is just how PHP is designed, so haven’t got much to do with Drupal.
This is also the reason why a lot of modules make a lot of inc files, to limit the amount of code needed to be parsed when hooks are fired.