Blog: PHP, Python, Linux, Web services & Continuous delivery
PHP Vagrant development instance with xhprof profiler
I've just added support for xhprof profiler into my base vagrant LAMP (PHP) stack . It automatically adds profiling to any PHP file that is served from the default virtual host (document root: /vagrant/www/) and includes a link at the footer of each page over to the xhprof output. Graphviz has also been installed so callgraphs are generated if you want something more visual.
For a quick confirmation test and an example of the profiler in action browse to http://localhost:8888/profiler.php after provisioning the instance. If you click on the link 'profiler output' at the foot of the page you should see the xhprof profiler output (fig 1) which contains another link over to the callgraph (Fig 2).
xhprof - PHP profiler, auto enabled for all PHP files served from /vagrant/www/
VM Port 80 (http) traffic forwarded to port 8888 on host - point your browser at localhost:8888
VM Port 22 (ssh) traffic forwarded to port 2222 on host - ssh to localhost:2222
VM Port 22 (ssh) traffic forwarded to port 9000 on host - ssh to localhost:9001
VM Port 22 (ssh) traffic forwarded to port 8000 on host - ssh to localhost:8000
A few mopre details on the Xhprof installation
xhprof vhost served on port 8000, forwarded to host on port 8000 too.
xhprof output is served via a separate virtualhost in which I symlink to the xhprofhtml and xhproflib directories that, in Debian, are placed in /usr/share/php/xhprof during xhprof installation.
Profiler output is stashed in /tmp/ and as such are not persisted between reboots
Header & footer PHP files are auto appended to all files served from the main vhost (rooted at /vagrant/www/) that enables the profiler and link over to the output
** If you are running more than one Vagrant instance concurrently then Vagrant may automatically assign different ports for forwarding traffic to the host. If this happens then the footer links to profiler output may need to be updated.
** Tested using Debian & Ubuntu base boxes