PHP Performance Profiling
To get the best understanding of how your PHP implementation runs under real conditions, you should do the profiling in an environment as close as possible to the real thing. Real data and many real or simulated client connections are helpful. You can create this environment by making a duplicate of your site and running HTTP benchmarking software or even using a couple of shell scripts and Wget to simulate user loads. Alternatively, you can do the profiling right on your live site.
As you've seen, using the profiling features of APD in your scripts causes the Web server to write out text files for every script access. That's obviously a very bad thing if you're trying to profile a live site, because data is dumped out faster than you can deal with it. Besides, it causes a slowdown on the server if your site has a lot of visitors--and if it didn't, you wouldn't be profiling it, would you? A useful little trick to get around the problem is to activate profiling only for page requests coming from your specific IP address. Doing so allows you to browse the live site and produce profile information without any action being taken on requests by other users.
This situation actually is pretty trivial to implement. Simply wrap the invocation of apd_set_pprof_trace() in a check for the requesting IP address, as shown below. Then, only your nominated client addresses cause the script to go into profiling mode:
<?php
$DEBUGIPS = array('203.222.90.204','192.168.0.23');
if(array_search($_SERVER[REMOTE_IP], $DEBUGIPS)) {
apd_set_pprof_trace();
}
?>
What now? Optimize your code, of course. I'm not going to tell you how to do that here, because it's way beyond the scope of this short article. But, at least now you have some insight into the internal workings of your application and won't be wasting time optimizing parts of your code that aren't really a problem. And when you do make changes, you have a benchmark against which you can test your code to see how the changes affect performance and efficiency.
Jonathan Oxer is the founder and Technical Director of Internet Vision Technologies, an Australian Web application development agency with clients around the world. He also is a Debian developer, current maintainer of apt-cacher and was organizer of the Debian Mini-Conf in Perth in January 2003 in association with Linux Conf Australia, where he also presented one of the technical papers. His first book, How to Hire a Web Developer and Stay Sane, will be published soon. His second book, The Debian Universe is being written live on-line, and his third and fourth books (How to Deploy Web Applications and Stay Sane and Disaster Proofing for Small Networks) already are underway.
email: jon@ivt.com.au
- « first
- ‹ previous
- 1
- 2
- 3
- 4
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- BASH script to log IPs on public web server
1 hour 8 min ago - DynDNS
4 hours 44 min ago - Reply to comment | Linux Journal
5 hours 16 min ago - All the articles you talked
7 hours 40 min ago - All the articles you talked
7 hours 43 min ago - All the articles you talked
7 hours 44 min ago - myip
12 hours 9 min ago - Keeping track of IP address
14 hours 34 sec ago - Roll your own dynamic dns
19 hours 13 min ago - Please correct the URL for Salt Stack's web site
22 hours 25 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
XDebug
Great article! APD is a great way to have a local and accurate profiling of your code. That is very useful in large applications since you can concentrate on a specific subsection of the code for optimization without being distracted by other stuff.
However, many times I find that using XDebug+Valgrind is a very good idea, because it can give you a good picture of how your entire application behaves and what are its most expensive (or critical) modules. Also the XDebug method is also the most unobtrusive I think (you only need very minor changes in your code for this to work).
apd not working from within apache server
HI, I am a newbie in APD, require your help to profile our PHP application. I have installed APD 1.0.1 on a Linux box and I am able to profile sample php scripts by firing them from shell as “php samplescript.php
Re: PHP Performance Profiling
Another nice way to analyze the trace file is by doing
$ pprof2calltree -f [pprof tracefile]
and then open the resulting file with KCachgrind
installation of APD not so easy
Installation of APD on my Debian system doesn't turn out to be so easy.
I just upgraded to Apache 2.2.0 and PHP5. I tried to install with the pear command, which gave me the following:
$ pear install apd
PHP version >= 5.0.0RC3-dev is required
apd: Dependencies failed
I also tried with:
$ apt-get install php5-apd
But php5-apd doesn't exist so I installed php4-apd which doesn't work.
Any idea's?
RE: installation of APD not so easy
I had the same problem installing apd on my gentoo machine.
It won't help you, but after the problems I had, I found out the for Gentoo apd is in portage (pecl-apd)
There might be some dependency problems, but once you fix those, apd works.
APD is a pecl package
I found out that to install apd on PHP 5 you need to use
pecl install apdcommand and notpear install apdapd install errors
has anyone solved this problem yet? tried pecl install apd, but no pecl command available. tried to install pecl, but instructions are too ambiguous -- Does apd REALLY require php v5.0 or is this a bug in the installation software?
After using "pecl install
After using "pecl install apd" and putting apd.so where php.ini wanted it there were a few more php.ini directives to add before the module showed up on my phpinfo page. See:
http://us.php.net/apd
Check the link
I managed to install efter looking trough this page: http://xdebug.org/install.php