Compile and install
wget http://pecl.php.net/get/xhprof-0.9.2.tgztar zxf xhprof-0.9.2.tgzcd xhprof-0.9.2/extension/sudo phpize./configure --with-php-config=/usr/local/php/bin/php-configsudo makesudo make install
Configure PHP. ini
[xhprof]extension=xhprof.so;; directory used by default implementation of the iXHProfRuns; interface (namely, the XHProfRuns_Default class) for storing; XHProf runs.;;xhprof.output_dir=<directory_for_storing_xhprof_runs>xhprof.output_dir=/tmp/xhprof
Note: For a 64-bit system, copy the xhprof. So file to the related lib64 directory.
Add the code to the PHP to be tested
<? Pho // CPU: Memory // if the two are together: xhprof_flags_cpu + Memory xhprof_enable (xhprof_flags_cpu + Memory); // PHP code to be tested $ DATA = xhprof_disable (); // return running data // This directory exists in the downloaded package of xhprof_lib. Remember to include the directory in the running PHP code include_once "xhprof_lib/utils/xhprof_lib.php "; include_once "xhprof_lib/utils/xhprof_runs.php"; $ objxhprofrun = new xhprofruns_default (); // The first parameter J is xhprof_disable () run information returned by the function // The second parameter is a custom namespace string (any string), // return the run ID, use this ID to view the relevant running result $ run_id = $ objxhprofrun-> save_run ($ data, "xhprof"); var_dump ($ run_id );
View running results
Copy the xhprof_lib & xhprof_html directory to the accessible address to access xxx/xhprof_html/index. php? Run = $ run_id & source = bluefrog. You can see the running status of your PHP code. The following describes some parameters that indicate that the random time includes all the execution time of the sub-function. Exclusive time/self time: the time consumed by the function execution, excluding the time consumed by the subtree. The time that wall time took or the time when the wall clock was suspended. CPU time user consumed time + kernel consumed time: CPU occupied by the CPU exclusive function itself, including the CPU occupied by the CPU used by the sub-function
Note:You need to use the ctype extension.
Xhprof Installation & use [reprint]