XHProf is a hierarchical PHP performance analysis tool. It reports the number of requests and various metrics at the function level, including the blocking time, CPU time, and memory usage. Now let's talk about how XHProf tests php performance in the development environment. Produced with a probability of 1%... XHProf is a hierarchical PHP performance analysis tool. It reports the number of requests and various metrics at the function level, including the blocking time, CPU time, and memory usage. Now let's talk about how XHProf tests php performance in the development environment.
Generate test data with a probability of 1%, and try not to affect the efficiency of the formal environment.
class XHProf { // private $XHProfPath = 'xhprof/'; private $XHProfPath = '/usr/local/apache/htdocs/xhprof/'; private $applicationName = 'sias_application'; private $sampleSize = 100; private static $enabled = false; public function XHProf_Start() { if (mt_rand(1, $this->sampleSize) == 1) { include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_lib.php'; include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); self::$enabled = true; } } public function XHProf_End() { if (self::$enabled) { $XHProfData = xhprof_disable(); $XHProfRuns = new XHProfRuns_Default(); $XHProfRuns->save_run($XHProfData, $this->applicationName); } }}
Test results:
Overall Summary Total Incl. Wall Time (microsec): 48,162 microsecsTotal Incl. CPU (microsecs): 32,994 microsecsTotal Incl. MemUse (bytes): 2,773,464 bytesTotal Incl. PeakMemUse (bytes): 2,867,664 bytesNumber of Function Calls: 749
The following test results show that the most time-consuming connection is to connect to the database, so we try to optimize the database as much as possible.
Address:
Reprinted at will, but please attach the article address :-)