Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /home/adam/sites/adamyoung.net/index.php:2) in drupal_send_headers() (line 1043 of /home/adam/sites/adamyoung.net/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home/adam/sites/adamyoung.net/index.php:2) in drupal_send_headers() (line 1043 of /home/adam/sites/adamyoung.net/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home/adam/sites/adamyoung.net/index.php:2) in drupal_send_headers() (line 1043 of /home/adam/sites/adamyoung.net/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home/adam/sites/adamyoung.net/index.php:2) in drupal_send_headers() (line 1043 of /home/adam/sites/adamyoung.net/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home/adam/sites/adamyoung.net/index.php:2) in drupal_send_headers() (line 1043 of /home/adam/sites/adamyoung.net/includes/bootstrap.inc).

PHP Script Timer

Every once in awhile I want to time the execution of certain areas of a script to weed out the slow parts. Every time I do it I end up making a new function like the one below. I'm sticking this here so I don't have to do it again next time. The code is real basic and can be extended easily to match your actual needs.

<?php
class timer {
	function timer() {
		$this->start = microtime(true);
	}
	function stop($show = true) {
		$this->end = microtime(true);
		$this->time = $time = $this->end - $this->start;
		if ($show) echo "Execution time: {$this->time} seconds";
	}
}

Example:

<?php
$timer = new timer;
// do heavy lifting here
$timer->stop();

This code only works for PHP 5. If you're using PHP 4 you should really upgrade but in the meantime read Example #1 on the microtime manual page to get it working.