John Esposito edits Refcardz at DZone, while writing a dissertation on ancient Greek philosophy and raising two cats. In a previous life he was a database developer and network administrator. John is a DZone Zone Leader and has posted 333 posts at DZone. You can read more from them at their website. View Full User Profile

Speed Up Your PHP Like Facebook

11.28.2011
| 8246 views |
  • submit to reddit

Facebook works well. NoSQL received a huge boost when people learned that Facebook uses Cassandra. But how much do people care that Facebook uses PHP?

Not just any PHP -- they 'rewrote the compiler', or rather wrote a translator that converts PHP into C++, then compiles with g++.

But Facebook did more for PHP: they also created XHProf, a PHP profiler with a (supposedly) easy-to-use HTML interface, designed to pinpoint exactly where your bottlenecks are appearing, so that you can optimize at every stage in the pipeline. Here's how the github readme describes it:

XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level call counts and inclusive and exclusive wall time, CPU time and memory usage. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.


If you haven't tried XHProf, you might want to look into it. Installation apparently requires a little nudging, but Nick Lewis just posted a full, practical guide to benchmarking and performance tuning your PHP and MySQL, using XHProf (as well as other techniques) -- a very nice overview of many common bottlenecks and how to open them up.

Nick also links to a great Drupal 6 performance wiki (no complaints now, plenty of users are still on Drupal 6), which is helpfully divided into subsections (big and small performance gains, bug fixes, etc.).

Both resources are worth checking out, especially if you're beginning to feel like PHP runs slowly (when in fact you haven't optimized nearly as well as you could).

 

Comments

Lucie Hauri replied on Thu, 2012/03/29 - 4:17pm

I will try to improve my facebook timeline speed. I will follow your tips.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.