Jump to content

Php Performance Issues


Recommended Posts

Hi all,

 

Not sure where to post my problem, so I hope I'll get some answers here.

I have a basic LAMP setup. All works fine

have APC installed

tweaked somewhat with mysql cache sizes etc

 

now I have 1 pageload in my application that takes +- 10 seconds to complete, and I can't seem to find out why...

 

What I checked:

I used firebug net view to see howlong the request takes, and it takes an average of 10 seconds, and is 25kb large (the response)

xdebug on the server tells me that the request start to finish takes 2442ms (2.4s)

 

(the request load is measured with xdebug off, if it's turned on the request takes 24+ seconds to complete...)

 

what am I missing?

why is that specific page request taking 10 seconds while the server sais it's done in 2.4.

The page doesn't contain a lot of javascript, so that's ruled out...

 

any other areas I can check? or does anyone else have an idea where the delay is located?

Edited by Darghon
Link to comment
Share on other sites

Executing SQL queries in a loop is a fairly common cause of slow pages.  For example doing something like:

$res=mysql_query('SELECT blah FROM bleh');
while ($row=mysql_fetch_assoc($res)){
   $res2=mysql_query('SELECT foo FROM boo WHERE blah='.$row['blah']);
}

 

The only way to find out what is going on really though is to profile the script to see what exactly is taking up the time.

 

If your PHP script seems to be running about as quick as possible but it still takes a long time for the page to render, you'll need to use browser dev tools like firebug or chrome's console to analyze where the time is being spent (loading resources such as scripts, parsing the dom, applying css, etc).

Link to comment
Share on other sites

Executing SQL queries in a loop is a fairly common cause of slow pages. For example doing something like:

$res=mysql_query('SELECT blah FROM bleh');
while ($row=mysql_fetch_assoc($res)){
  $res2=mysql_query('SELECT foo FROM boo WHERE blah='.$row['blah']);
}

 

The only way to find out what is going on really though is to profile the script to see what exactly is taking up the time.

 

If your PHP script seems to be running about as quick as possible but it still takes a long time for the page to render, you'll need to use browser dev tools like firebug or chrome's console to analyze where the time is being spent (loading resources such as scripts, parsing the dom, applying css, etc).

 

Well the 2 points in the end are basicly the things I've checked so...

and I indeed have nested statements etc, but I have to. otherwise I won't be able to process my business rules that I have specified for each table/object.

 

anyway, I managed to solve the issue.

The cachegrind result was wrong basicly, and the request was taking 4x longer than reported.

I tinkered somewhat with the loaded statements, and cached them inside the objects that called them, resulting in a speed gain.

 

request now takes 3 seconds to load into the browser, and I'm happy with the results.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.