Install and use Xhprof, and install and use Xhprof
Install xhprof (if there is an error, make clean and recompile it)
1. Download xhprof
# Wget, can be compiled again)
# Tar zxf xx.gz (next file)
2 cd xhprof
Cd extension
/Usr/local/php/bin/phpize (use the phpize path in your environment)
. /Configure -- enable-xhprof -- with-php-config =/usr/local/php/bin/php-config (path of your own php-config environment, installation will fail if the path is wrong)
Make & make install, I tried it several times to make it quite depressing)
3. Create a file/usr/local/etc/php. d/xhprof. ini (or add it at the end of php. ini)
Content: extension = xhprof. so;
Xhprof. output_dir =/data/logs/Appstore/Xhprof/
4. Open phpinfo () to check whether the extension is added (if not, recompile until the extension is successful)
If you do not need to display the graph, you can use it now. Create an xhprof domain name and test it in sample. php In example.
If you want to display the graph, go down.
Install png. (check whether the libpng extension is available online. If yes, you do not need to install it)
1 wget http://nchc.dl.sourceforge.net/project/libpng/libpng15/1.5.1/libpng-1.5.1.tar.gz
2 tar zxf libpng-1.5.1.tar.gz
3 cd libpng-1.5.1
4./configure -- with-php-config =/usr/local/php/bin/php-config
5 make
6 make install
Install Graphviz
Install Graphviz
1 wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz
2 tar zxf graphviz-2.24.0.tar.gz
3 cd graphviz-2.24.0
4./configure -- with-php-config =/usr/local/php/bin/php-config -- with-png = yes
5 make
6 make install
If/usr/bin/dot is generated
At this time, you will find that the figure still cannot be displayed, prompting dot-png fail, that is, he cannot find the dot path, the dot path in your xhprof/xhprof_lib/utils/callgraph_utils.php is/usr/bin/dot (your own dot address)
At this time, the figure basically came out.
See the figure below to see if it is spectacular. When it comes out, the sense of accomplishment burst.
Next we will explain how to integrate it into your own code.
During analysis, skip the built-in function xhprof_enable (XHPROF_FLAGS_MEMORY, array ('ignored _ functions' => array ('call _ user_func ', 'Call _ user_func_array ')));
Usage mechanism:
I have encapsulated a class myself, or I can directly use
After the class is called at the beginning of the function, a file will be generated in your xhprof. output_dir.
Under/data/logs/Appstore/Xhprof/, a file such as 54a3a2606e75b. top-size-10-page-1-list.json.xhprof is generated,
If $ run_id = $ xhprofRuns-> save_run ($ xhprofData, $ name); the default name is xhprof_foo, if you want to directly see the parsing file generated by the interface in the generated file,
You can specify the name in this part.
$ Name = str_replace ('/', '-', $ _ SERVER ['request _ URI ']);
$ Name = substr ($ name, 1 );
$ XhprofRuns = new XHProfRuns_Default ();
$ Run_id = $ xhprofRuns-> save_run ($ xhprofData, $ name );
Then you can view the results based on the domain name you configured, such
Access http: // xxx/xhprof_html/index. php? Run = 54a3a2606e75b & source = top-size-10-page-1-list.json
Click view full callgraph to view details.
Http: // xxx/xhprof_html/callgraph. php? Run = 54a3a2606e75b & source = top-size-10-page-1-list.json