PHP pages loading slow

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

PHP pages loading slow

Post 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?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post 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.
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

a way to solve this is using a cache

it will then only execute the sql query's
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post 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
Post Reply