Matthew Turland has a post to his site sharing his experience with the PHPUnit and XHProf combination...and the unfortunate result that made every test fail.

I ran into an issue recently while trying to run PHPUnit tests in an environment using XHProf. Google didn’t prove to be much help, so I thought I’d document the problem and solution here for posterity.

When I ran my tests, each failed with the same cryptic error and no backtrace: "Attempted to serialize unserializable builtin class PDO" The cause was the culmination of two rather unfortunate circumstances.

He shares the two problems that causes this issue - one being XHProf's use of globals (where its PDO connection is stored) and the other is the @backupGlobals setting in PHPUnit that's enabled by default. This makes PHPUnit to try to backup that PDO connection by serializing it but can't, hence the failure. He points out a pull request that aims to fix the issue but recommends disabling the globals backup for the time being if you don't have a need for it.

The Platform.sh blog has a post showing you how to create flamegraphs with XHProf for your application's execution and overall performance. A "flamegraph" is just a different sort of graph stacking up the execution times for the methods and functions in your application so they look more like a "flame" than just numbers.

One of the most frequent needs a web application has is a way to diagnose and evaluate performance problems. Because Platform.sh already generates a matching new environment for each Git branch, diagnosing performance problems for new and existing code has become easier than ever to do without impacting the behavior of a production site. This post will demonstrate how to use a Platform.sh environment along with the XHProf PHP extension to do performance profiling of a Drupal application and create flamegraph images that allow for easy evaluation of performance hotspots.

While they show it at work on a Platform.sh instance, the method can be altered slightly to work with your own application with the right software installed. Their example uses the brendangregg/FlameGraph library to do the majority of the graphing work. He shows how to have the code switch on XHProf during the execution and where to put the file for later evaluation. They include the resulting directories and files created from the execution and how to view the resulting (SVG-based) graphs directly in a browser.

Lorna Mitchell has a new post today showing you how you can use XHGui in a virtual machine, sorting the resulting performance data on the VM rather than your local machine.

I'm doing some performance tuning on a project at the moment and my favourite tool is still XHGui - but it's designed to run on the same machine as its victim and since this is a vagrant VM, the chances of me destroying the machine and therefore the data are pretty high! Instead, I set it up to store the data onto the host and I thought I'd share how I did that. All these instructions for Ubuntu on both host and guest, and I've tried not to be specific about the vagrant elements in order to focus on how the pieces fit together rather than what you should type.

She walks you through all the steps you'll need to get the software up and running as well as configuring the actual guest VM to direct the data to the right place. She sets up the data source to push the results into (a MongoDB) and configures the PHP installation with an "auto prepend" of the XHGui header file. Finally, she includes the commands you'll need to view the data on the VM itself, running the built-in PHP web server as an ad-hoc instance on the VM itself.

On the Qandidate.com blog there's a new post showing how to set up the PHP profiling tool XHProf/XHGui using Ansible for setup and configuration. Ansible is a radically simple IT orchestration engine that makes your applications and systems easier to deploy.

Once in a while I think about profiling my web applications to see if I can get them to run faster. There are cool tools out there like XHProf and XHGUI to help you do exactly that. And then I remember it took me quite some time to get it all set up... But now that I've started using Ansible I decided to document the set up process and share it with you. Today I will walk you through my Ansible role for setting up everything you need for profiling your first PHP script.

He starts with a checklist of things to be sure you have installed first (including XHProf and XHGui) and links to his yml configuration to run a "profiling" command. An example of the result (the XHGui HTML output) is also included.

Today I set up my development environment so I can use XHProf to profile PHP scripts when needed, and it was pretty easy. [...] XHProf is a PECL package, and can be easily installed by using standard PECL commands.

He walks you through the installation of the PECL package (you'll need to use the command line for this one) and how to add the module to your php.ini to enable it. Once you restart your web server, you can start the debugging using the xhprof_enable function and then the xhprof_disable function to end the testing and retrieve the data for processing. He also includes a bit of output from his own pass-through script to show the results.

Lorna Mitchell has a new post today showing you how to install XHGui to help with profiling your application for performance and processing issues.

If you're not familiar with XHGui it's a fabulously easy and friendly way to profile your application; to understand which method calls in a page take the time and how many times they are made, so you can improve the performance of your application. All these instructions are for my 32-bit Ubuntu 12.10 system, hopefully they will work for you or you'll be able to adapt them as appropriate.

She lists the dependencies you'll need to have installed before you can get XHGui working correctly including a MongoDB instance and the PECL xhprof extension. With those all set to go, you can go grab the latest XHGui from github and drop it into place.

Mark Story & I are pleased as punch to introduce XHGui on MongoDB. Our goal was to get as close to the original feature set of the tool I worked on a few years ago (which leveraged the starting point provided by Facebook) and then to release what we had. What we’ve got now works; there’s still a good distance to go, but we think it’s far enough that we can ask for help form the community at large.

The tool collects XHProf data and stores it into a MongoDB database and allows you to viewrecent activity. There's a few warnings that he includes with the post, so be sure to read those through if you plan on using the tool.

On PHPMaster.com today Matt Turland has an article posted about using XHProf and XHGui to find the performance issues in your application and profile them to help optimize things.

Profiling is the process of measuring the execution time of each function or method call involved in servicing a single page request. The data collected from this process can reveal issues such as a particular method taking a long time to execute or being called a large number of times. Profiling a PHP script generally requires installing a PHP extension. The two more popular extensions for this purpose are Derick Rethans‘ Xdebug and Facebook’s XHProf. This article will focus on XHProf.

He walks you through the installation of both and shows you some sample results of the profiling of a simple application and how you can compare the results across profiling runs. Additionally, if you install graphviz support, you can generate the call stack output in a visual form to make for easier consumption.

XHProf will provide you with a hierarchical profile of the functions your application calls, allowing you to follow the chain of events that lead up to resource intensive code running. You’ll be able to see exactly how much wall time (the actual time elapsed), CPU time and memory your application uses. This tutorial will help you get XHProf installed on your server, and integrated with your CodeIgniter application via hooks so that you can start profiling your application, in a production environment, straight away. Everything you see here was written for Ubuntu 10.04 – the latest LTS release at the time of writing.

They walk you through the installation of the tool (via a wget of the source), show you how to integrate it with CodeIgniter via hooks and include a simple class that is called to execute and report on the findings. Some sample output is included as well as some general tips on interpreting the results.