Jump to content


Photo

Php Performance Issues


  • Please log in to reply
2 replies to this topic

#1 Darghon

Darghon

    Advanced Member

  • Members
  • PipPipPip
  • 75 posts

Posted 16 November 2012 - 05:42 AM

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, 16 November 2012 - 05:44 AM.


#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,667 posts
  • LocationBonita, FL

Posted 16 November 2012 - 05:53 AM

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).
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 Darghon

Darghon

    Advanced Member

  • Members
  • PipPipPip
  • 75 posts

Posted 16 November 2012 - 06:53 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com