One often needs to display the page generation time for every page.

The excellent devel module provides this feature, and other important ones as well, like displaying queries and the time it takes each one to execute, and much more.

However, there are sometimes side effects to enabling the devel module on 4.6 and 4.7, that may manifest itself in certain situations. For example, showing errors on the screen directly.

If you want the timer functionality without the full devel, here is a tiny module that displays the timer at the bottom of every page.

To configure it, you have to add the following to the bottom of your settings.php file.

   $conf = array(
'dev_timer' => 1,
);

Then copy the following code to a file named zztimer.module in your modules directory. Enable it like any other module.

<?php

define('TIMER_PRINT', 'dev_timer');

function zztimer_exit() {
global $timer;

if (variable_get(TIMER_PRINT, FALSE)) {
list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec;
$diff = round(($stop - $timer) * 1000, 2);
$diff = number_format($diff, 2);
print t('Page generated in %time ms.', array('%time' => $diff));
}
}

Enjoy!

Comments

Wed, 2007/02/14 - 02:14

Isn't there a '?>' missing at the end of that?

My drupal site went dead when I inserted this code -- even with the missing ?>

Tue, 2007/09/11 - 06:03

Sorry, but what how do I convert output into seconds?

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting