Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created January 6, 2012 08:34
Show Gist options
  • Select an option

  • Save psiborg/1569722 to your computer and use it in GitHub Desktop.

Select an option

Save psiborg/1569722 to your computer and use it in GitHub Desktop.
PHP Script Template
<?php
/* ===========================================================================
* $Id$
*
* @fileoverview
*
*
* @author Jim Ing (@jim_ing)
* ===========================================================================
*/
$log_file = 'app.log';
$log_date_format = 'Y/m/d H:i:s';
//---[ Main ]-----------------------------------------------------------------
try {
$time_start = microtime(true);
$fh = fopen($log_file, 'a');
fwrite($fh, date($log_date_format, time()) . " - " . 'Start' . PHP_EOL);
$output = '';
//------------------------------------------------------------------------
//------------------------------------------------------------------------
$time_elapsed = round((microtime(true) - $time_start), 4);
$output .= PHP_EOL;
$output .= 'Elapsed time: ' . $time_elapsed . ' secs.' . PHP_EOL;
$output .= 'Peak memory: ' . round((memory_get_peak_usage() / 1024)) . ' KB' . PHP_EOL;
header('Content-Type: text/plain; charset=utf-8');
echo $output;
fwrite($fh, $output);
fwrite($fh, date($log_date_format, time()) . " - " . 'End' . PHP_EOL);
fwrite($fh, '------------------------------------------------------------------------------' . PHP_EOL);
fclose($fh);
}
catch (Exception $e) {
header('Content-Type: text/plain; charset=utf-8');
die('Exception: ' . $e->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment