Environment :
php 5.2.14
xhprof 0.9.2
graphviz 2.26.3
1. Download and install xhprof :
[codesyntax lang=”bash”]
$ wget http://pecl.php.net/get/xhprof-0.9.2.tgz $ tar -xzf xhprof-0.9.2.tgz $ cd xhprof-0.9.2 $ cp -r xhprof_html xhprof_lib /data/vhosts/www/ $ cd extension $ phpize $ ./configure $ make $ make install
[/codesyntax]
2. Modify php.ini :
[codesyntax lang=”ini”]
extension = "xhprof.so" [xhprof] xhprof.output_dir = "/data/xhprof"
[/codesyntax]
3. Restart apache (or nginx and php-fpm) and see xhprof section :
4. Start profiling file_to_profile.php :
[codesyntax lang=”php”]
// start xhprof xhprof_enable(); /** * your application code * ...... * ...... */ $xhprof_data = xhprof_disable(); $xhprof_root = '/data/vhosts/www/xhprof/'; include_once $xhprof_root . "xhprof_lib/utils/xhprof_lib.php"; include_once $xhprof_root . "xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xr"); echo 'see xhprof result';
[/codesyntax]
5. Additional effect with graphviz :
[codesyntax lang=”bash”]
# download and install graphviz $ wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz $ tar -xzf graphviz-2.26.3.tar.gz $ cd graphviz-2.26.3 $ ./configure --prefix=/usr/local/graphviz $ make $ make install
[/codesyntax]
to be continue …