<?php // A function that records the time when it is called function profile($dump = FALSE) { static $profile; // Return the times stored in profile, then erase it if ($dump) { $temp = $profile; unset($profile); return ($temp); } $profile[] = microtime(); } // Set up a tick handler register_tick_function("profile"); // Initialize the function before the declare block profile(); // Run a block of code, throw a tick every 2nd statement /** * * decalre 体中 没执行ticks条低级语句就会执行一次callback * 如下例 *for循环整个算一个低级语句 echo 算一个低级语句 * 也就是说 一个for循环执行完 算2次 那么 * ticks=4 就是执行2个for循环后 会调用一次callback * 所以最后数组中会有25个元素 */ declare(ticks=4) { for ($x = 1; $x < 50; ++$x) { // echo similar_text(md5($x), md5($x*$x)), "<br />;"; echo $x.'<br/>'; } } // Display the data stored in the profiler print_r(profile (TRUE)); ?>