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
Visitor (not verified)
Typo?
Wed, 2007/02/14 - 02:14Isn't there a '?>' missing at the end of that?
My drupal site went dead when I inserted this code -- even with the missing ?>
Khalid
No
Wed, 2007/02/14 - 10:03PHP files do not have to end with ?>, and that includes .module files.
Did you create that as a .module or pasted it in a node or what?
--
2bits -- Drupal and Backdrop CMS consulting
Visitor (not verified)
Output
Tue, 2007/09/11 - 06:03Sorry, but what how do I convert output into seconds?
Khalid
Divide by 1000
Tue, 2007/09/11 - 10:241 second = 1000 milliseconds.
--
2bits -- Drupal and Backdrop CMS consulting