Created
January 6, 2012 08:34
-
-
Save psiborg/1569722 to your computer and use it in GitHub Desktop.
PHP Script Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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