Skip to content

Instantly share code, notes, and snippets.

@suvene
Created April 8, 2014 06:33
Show Gist options
  • Save suvene/10097210 to your computer and use it in GitHub Desktop.
Save suvene/10097210 to your computer and use it in GitHub Desktop.
function formatMicrotime($time, $format = null){
if (is_null($format)) {
$formated = sprintf('%0.5f', $time);
} else {
$sec = (int)$time;
$msec = (int)(($time - $sec) * 100000);
$formated = date($format, $sec) . '.' . $msec;
}
return $formated;
}
function printLog($message, $echo = false, $startTime = null, $endTime = null) {
if (is_null($startTime)) {
$startTime = $GLOBALS['gStartTime'];
}
if (is_null($endTime)) {
$endTime = microtime(true);
}
$formatedTime = formatMicrotime($endTime, 'Y-m-d H:i:s');
$elapseTime = $endTime - $GLOBALS['gLapStartTime'];
$elapseTime = formatMicrotime($elapseTime);
$msg = $formatedTime . "\t" . $elapseTime . "\t" . $message . "\n";
if ($echo) {
print $msg;
}
error_log($msg, 3, "process_log.txt");
$GLOBALS['gLapStartTime'] = $endTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment