Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the performance consequences of PHP code

How can you determine the performance consequences of your PHP code if you are not familiar with the internals? Are there ways to figure out how your code is being executed (besides simply load testing it)? I am looking for things like memory usage, the execution time for algorithms.

Perhaps Joel would say, "learn C, then read the internals", but I really don't have time to learn C right now (though I'd love to, actually).

like image 592
Sam McAfee Avatar asked Sep 09 '08 00:09

Sam McAfee


People also ask

What causes performance bottlenecks in PHP?

Lack of caching strategy Imagine that you have a PHP content management system that powers a news website. Each time a visitor clicks on a story, a database query is executed to retrieve the story content. It's easy to see that thousands of visitors to hundreds of stories could put considerable strain on a database.


2 Answers

Use the Xdebug extension to profile PHP code.

like image 85
Jordi Bunster Avatar answered Oct 21 '22 22:10

Jordi Bunster


If you're not familiar with valgrind or similar, then to add to @Jordi Bunster's answer...

When you've had profiling on in Xdebug, you can open the dumped profile files in KCacheGrind or WinCacheGrind to get a graphical view of what is taking the time in your code.

Fortunately the xdebug documentation also explains this in detail as well as how to interpret the results: http://xdebug.org/docs/profiler

like image 3
reefnet_alex Avatar answered Oct 21 '22 22:10

reefnet_alex