Bootstrap And Your Module

I had an interesting gotcha this afternoon. With Drupal 6.x came a new hook, hook_boot(). It supercedes the !$may_cache behaviour in Drupal 5.x by providing a hook that any code which *must* run on all pages, cached or otherwise, can be placed in.

This is pretty useful, because unlike hook_init() which only fires on pages that are not cached, hook_boot() always fires.

A word of warning though. I started out writing a module today using hook_init() and changed it after a time, as I realised hook_boot() was more suitable. For some weird reason though, my hook was not behaving any differently. It was as though it was still a hook_init() implementation.

Turns out if you create a hook_boot() or hook_exit() implementation in an existing module, you have to go to the admin/modules/list page. This will refresh the system table in the Drupal database and set the bootstrap column to 1, telling Drupal to execute the new functions on bootstrap. Otherwise they will not function correctly.

Post new Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.