Tech Blog :: How to install xhprof on OSX (Snow Leopard or Lion) and XAMPP
How to install xhprof on OSX (Snow Leopard or Lion) and XAMPP
Note: The same instructions apply to XDebug and possibly every other PECL module in this environment.
XHProf is a very neat PHP profiler. Documentation and general installation instructions are not hard to come by, but none of the examples I found had the right steps for my particular setup, Mac OSX Lion with XAMPP running php 5.3. (Should apply also to OSX Snow Leopard.) So this post fills in that hole; for everything else regarding xhprof look elsewhere.
The problem is the "architecture" that xhprof compiles to; OSX and xhprof are 64-bit but XAMPP is apparently 32-bit. (If you're using MAMP instead of XAMPP, you'll have a similar problem; here is a solution for that.)
After trying multiple variations, the solution that worked was adapted from this memcached-on-xampp post):
- Download the latest copy of xhprof
sudo phpize(not sure if this is actually necessary. You may run into problems here; find the solution to that elsewhere.)
- If you've been trying other methods that failed, clean up the old junk:
sudo make clean
- The most important part:
sudo MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
sudo make install
- Add to your php.ini:
xhprof extension = xhprof.so xhprof.output_dir = "/Applications/XAMPP/xhprof-logs"
php -i | grep xhprof and if it worked, it should tell you which version you're running. If it fails, it will say, xhprof.so: mach-o, but wrong architecture in Unknown on line 0.
Update: It's worth mentioning, you'll probably also need to install Graphviz so xhprof can find the
dot utility to generate graphics.