Skip to content

Commit 4155172

Browse files
committed
xhprof
0 parents  commit 4155172

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

php-xhprof-install.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
XHPROF
2+
======
3+
4+
https://stojg.se/blog/2011-08-27-install-xhprof-for-php5-on-centos-ubuntu-and-debian
5+
6+
Install graphviz:
7+
8+
# for centos (WORK)
9+
sudo yum install graphviz
10+
# for ubuntu and debian
11+
sudo apt-get install graphviz
12+
13+
Continue:
14+
15+
sudo pecl config-set preferred_state beta
16+
sudo pecl install xhprof
17+
18+
See error:
19+
20+
running: phpize
21+
Cannot find config.m4.
22+
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
23+
24+
ERROR: `phpize' failed
25+
26+
To fix bug:
27+
28+
# NOTE using 0.9.4 at work
29+
wget http://pecl.php.net/get/xhprof-0.9.2.tgz
30+
tar zxf xhprof-0.9.2.tgz
31+
cd xhprof-0.9.2/extension
32+
phpize
33+
./configure
34+
make
35+
sudo make install
36+
37+
Enable it:
38+
39+
# for centos
40+
sudo touch /etc/php.d/xhprof.ini
41+
# for ubuntu and debian
42+
sudo touch /etc/php5/conf.d/xhprof.ini
43+
44+
Edit config file and write this:
45+
46+
[xhprof]
47+
extension=xhprof.so
48+
xhprof.output_dir="/tmp/xhprof"
49+
50+
Restart apache:
51+
52+
# for centos
53+
sudo /etc/init.d/httpd restart
54+
# for ubuntu and debian
55+
sudo /etc/init.d/apache2 restart
56+
57+
Clone xhprof repo where you keep all your code:
58+
59+
git clone https://github.com/facebook/xhprof.git
60+
61+
Put this sample code in your app's index.php; be careful to point $XHPROF_ROOT to the repo you clones:
62+
63+
<?php
64+
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
65+
for ($i = 0; $i <= 1000; $i++) {
66+
$a = $i * $i;
67+
}
68+
69+
$xhprof_data = xhprof_disable();
70+
$XHPROF_ROOT = "/data/xhprof/";
71+
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
72+
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
73+
74+
$xhprof_runs = new XHProfRuns_Default();
75+
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
76+
echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";
77+
exit();
78+
?>
79+
80+
Create a symbolic link in your app code so that xhprof is accessible (alternatively, you could do a vhost, etc):
81+
82+
cd /webroot/public/yada-yada/
83+
ln -s /path/to/xhprof/repo xhprof
84+
85+
Now hit the app to generate an xhprof report and follow the link.

0 commit comments

Comments
 (0)