Php performance monitoring extension xhprof is a good tool in general. This section describes how to install and use it in ubuntu. Install xhprof:
- Wget http://pecl.php.net/get/xhprof-0.9.2.tgz
-
- Tar zxf xhprof-0.9.2.tgz
- Cd xhprof-0.9.2/extension/
- Sudo phpize
- ./Configure -- with-php-config =/usr/local/php/bin/php-config
- Sudo make
- Sudo make install
-
To view the debugging result in graphical mode, you must install graphviz. in ubuntu, you can directly install graphviz using apt-get. the command is sudo apt-get install graphviz. If it is another system, it may take twists and turns. the command is as follows:
- Wget http://www.graphviz.org/pub/graphviz/stable/sources/graphviz-2.24.0.tar.gz
- Tar zxf graphviz-2.24.0.tar.gz
- Cd graphviz-2.24.0
- ./Configure
- Make & make install
Configure php. ini Add the following to 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 =
- Xhprof. output_dir =/tmp/xhprof
-
Note: For a 64-bit system, copy the xhprof. so file to the relevant lib Directory (lib64) After the modification, restart apache and check phpinfo. There should be information about xhprof. Add the code to the php to be tested
- // Cpu: xhprof_flags_cpu memory: xhprof_flags_memory
- // If the two are together: xhprof_flags_cpu + xhprof_flags_memory
- Xhprof_enable (xhprof_flags_cpu + xhprof_flags_memory );
-
- // Php code to be tested
- $ Data = xhprof_disable (); // return the running data
-
- // This directory exists in the downloaded package. 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 the running information returned by the xhprof_disable () function.
- // The second parameter is a custom namespace string (any string ),
- // Return the running id. use this id to view the relevant running result.
- $ Run_id = $ objxhprofrun-> save_run ($ data, "xhprof ");
- Var_dump ($ run_id );
View the running result: copy the xhprof_lib & xhprof_html directory to the accessible address. Access xxx/xhprof_html/index. php? Run = $ run_id: you can see the running status of your php code. $ run_id is the content output on the above page. remember to include two files under xhprof_lib, if you do not want to use this method, you can directly output the relevant print information, that is, directly print the $ data value above. Parameter description: Implicit time includes all execution times of sub-functions. 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 |