/** * 跟踪程序运行, 记录一些时间等情况。 * * @param string $out 是否在页面输出 */ public static function time($key = null, $name = 'Tracer', $out = false) { if (empty(self::$timeTracer)) { self::$timeTracer = array(0 => array('name' => 'start.', 'time' => time())); } $now = microtime(true); // 时间跟踪器总数 $count = !empty(self::$timeTracer) ? count(self::$timeTracer) : 0; // 距离上一个跟踪器所耗时间 end(self::$timeTracer); $last_key = key(self::$timeTracer); $time = $now - self::$timeTracer[$last_key]['time']; // 添加进时间跟踪器 $key = !empty($key) ? $key : $count; self::$timeTracer[$key] = array('name' => $key, 'time' => $now); if ($out) { $txt = "{$key} timer_{$count}: {$now} ,take {$time}"; echo "<br>" . $txt . "<br>"; } }