Bootstrap And Your Module

Photo of Greg Harvey
Thu, 2008-11-20 17:20By greg

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.