Page 1 of 1

PHP pages loading slow

Posted: Tue Feb 13, 2007 2:03 am
by Mr Tech
Some of my PHP pages are loading slow probably because there is some code that's taking to long.

Is there any software or ways for PHP to check what happens when a script loads and how long it takes. I'm pretty sure there is on for PHP 5 but what about PHP 4?

Posted: Tue Feb 13, 2007 2:29 am
by CoderGoblin
I tend to add debug information to check timing based on microtime. If you are using a database, this is probably your sticking point. One common mistake is to have multiple selects where you could use a join (even if it is an outer join :wink:). Another is using "SELECT *" where you only want one or two columns. With the Zend Framework Zend_DB you have something call a profiler which times SQL commands automatically but this should only be used if you use the Zend Framework already.

Without knowing anything about your code it is hard to give a pointer.

Posted: Tue Feb 13, 2007 3:33 am
by Mordred
It's called a profiler, some PHP IDEs have one, I use Zend Studio, but I can't recall if there is a free and open source alternative.

Posted: Tue Feb 13, 2007 7:43 am
by ryuuka
a way to solve this is using a cache

it will then only execute the sql query's

Posted: Tue Feb 13, 2007 7:59 am
by onion2k
Mordred wrote:I can't recall if there is a free and open source alternative.
I can. It's called X-Debug ( http://xdebug.org/ ). It's ace, but rather complicated.

Posted: Tue Feb 13, 2007 8:46 am
by Mordred
Btw, a passable profiler can be built on top of microtime(), as long as you're okay with the overhead and you're aware that for multiple calls the measurements are skewed. If there's interest I can clean my code a bit and post it around, but it's pretty basic stuff, here's a sample report:

Image