Run a check on every page load programmatically Drupal 7.

I have a site with Single Sign On (SSO) implemented. The implementation of the features is complete and the site is running perfectly.

Now, I have a requirement where I am supposed to check whether the session of the central server (on root of the domain and not using Drupal) is alive. I can do this by checking the availability of the session cookie on the root domain. And if the session is not active the user is logged out of Drupal.

I tried implementing it inside hook_init() but it only works for non-cached pages, whereas I want my code to be triggered on every page.

I also had a look at hook_boot() which runs even on cached pages. But, it is called while Drupal is still in bootstrap mode; even before themes and modules are loaded into memory. Which would mean that I would not be able to check the status of the user (whether the user is logged in?), because the user module and the included file session.inc would not be present in the memory while the execution of this hook.

So my question is which function (or hook) should I use which would execute on all pages(cached and non-cached) and which would give me access to common user properties (e.g. global $user object, user_is_logged_in() function etc)?
(I'm assuming Drupal 6)

Looking at bootstrap.inc, hook_boot is called on all pages, as long as agressive caching hasn't been turned on.

At this point the global $user variable should already exist (page_get_cache, which is called before hook_boot, makes use of it for example). module.inc has also been included, so you can use the functions included in that file to check for module existance and load them if necessary.

So, hook_boot looks like a good choice.