How often is settings.php called? And is $user available to it? I'm thinking about adding some handling to the settings.php code, to set the ini_set('session.gc_maxlifetime', 2880); value based on the role of the logged it (or not logged in) user.

i.e. for admin role, moderator role, I'd set a real long value so as to basically not ever get logged out due to idling too long, while writing a long article, or whatever, while for "lesser" roles, like a regular member, they'll get a regular, shorter maxlifetime.

My 2 questions:

1) Is the Global $user var available within settings.php, so I can check it for the user's roles?

2) How often does it get called? Only once during initial site load? Or every time a user loads a page? I don't want to be (re)setting the value every time a page loads.
The settings.php file is included on the first bootstrap phase (DRUPAL_BOOTSTRAP_CONFIGURATION), while the global $user is initialized on DRUPAL_BOOTSTRAP_PAGE_CACHE or DRUPAL_BOOTSTRAP_SESSION, which are both later bootstrap phases.

The settings.php file is included each times Drupal bootstraps, which means every time Drupal serves a page, including the ones served from its cache. As such, the settings.php file can use plain PHP functions or a restrict set of Drupal functions; in both the cases, the code cannot access the user variable. It is not even possible to initialize it using the database, since the database connection is initialized after the file has been included. (The obvious reason is that the database settings are contained in the settings.php file.)

Reference


drupal_bootstrap()