PHP Optimization question
PHP Optimization question
am 13.01.2008 07:42:11 von IanReardon
I'm trying to optimize a php project of mine and I'm running into some
problems.
Overall the page takes about .4-.5 seconds to render (just the code,
i'm recording the time at start and finish of execution) on a my dual
core server with nothing else running (other than httpd and mysqld)
I've optimized my queries, total mysql query time is about .1 to .12
seconds total.
For some reason the part of my php that takes the longest to execute
is a rather large section of html code with some echo $someVar; ?>
sprinkled in. There is no logic or functional calls, yet this block
of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
Can anyone recomend ways to find out where my php code is executing
slow?
Thank you
Re: PHP Optimization question
am 13.01.2008 09:06:56 von radmission05
On Jan 12, 10:42 pm, IanRear...@gmail.com wrote:
> I'm trying to optimize a php project of mine and I'm running into some
> problems.
>
> Overall the page takes about .4-.5 seconds to render (just the code,
> i'm recording the time at start and finish of execution) on a my dual
> core server with nothing else running (other than httpd and mysqld)
>
> I've optimized my queries, total mysql query time is about .1 to .12
> seconds total.
>
> For some reason the part of my php that takes the longest to execute
> is a rather large section of html code with some echo $someVar; ?>
> sprinkled in. There is no logic or functional calls, yet this block
> of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
>
> Can anyone recomend ways to find out where my php code is executing
> slow?
>
> Thank you
is it your local machine? or hosting..its maybe the bandwidth, or
maybe you have internet protection. that scan the internet content
before it render the code.
Re: PHP Optimization question
am 13.01.2008 12:36:02 von colin.mckinnon
On 13 Jan, 08:06, "radmissio...@gmail.com"
wrote:
> On Jan 12, 10:42 pm, IanRear...@gmail.com wrote:
>
>
>
> > I'm trying to optimize a php project of mine and I'm running into some
> > problems.
>
> > Overall the page takes about .4-.5 seconds to render (just the code,
> > i'm recording the time at start and finish of execution) on a my dual
> > core server with nothing else running (other than httpd and mysqld)
>
> > I've optimized my queries, total mysql query time is about .1 to .12
> > seconds total.
>
> > For some reason the part of my php that takes the longest to execute
> > is a rather large section of html code with some echo $someVar; ?>
> > sprinkled in. There is no logic or functional calls, yet this block
> > of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
>
> > Can anyone recomend ways to find out where my php code is executing
> > slow?
>
> > Thank you
>
> is it your local machine? or hosting..its maybe the bandwidth, or
> maybe you have internet protection. that scan the internet content
> before it render the code.
Unlikely to be a bandwidth problem unless the geenrated page is very
large and being flushed intermittently to the browser.
Sounds like a job for XDebug + Kcachegrind
C.
Re: PHP Optimization question
am 13.01.2008 14:30:24 von seaside
On 13 Jan., 07:42, IanRear...@gmail.com wrote:
>
> I've optimized my queries, total mysql query time is about .1 to .12
> seconds total.
Although mySQL takes just a few seconds, did you use an index for
attributes
in WHERE clauses?
Additionally, MySQL disables its cache by default. You need to enable
it
manually to make MySQL return cached result sets.
Moreover, note that MySQL only assumes queries to be identical, if
they are textually identical. Even a a single added space make MySQL
compute the query again and no use the cache.
Re: PHP Optimization question
am 13.01.2008 15:13:12 von Jerry Stuckle
IanReardon@gmail.com wrote:
> I'm trying to optimize a php project of mine and I'm running into some
> problems.
>
> Overall the page takes about .4-.5 seconds to render (just the code,
> i'm recording the time at start and finish of execution) on a my dual
> core server with nothing else running (other than httpd and mysqld)
>
> I've optimized my queries, total mysql query time is about .1 to .12
> seconds total.
>
> For some reason the part of my php that takes the longest to execute
> is a rather large section of html code with some echo $someVar; ?>
> sprinkled in. There is no logic or functional calls, yet this block
> of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
>
> Can anyone recomend ways to find out where my php code is executing
> slow?
>
> Thank you
>
How do you know it's taking that long for the PHP to execute? I
wouldn't expect it to take very long to process the HTML code. You
didn't show us what echo statements you had, but I wouldn't expect a few
of those to take long, either.
There can be a lot of other things involved. For instance, during this
code, you may have filled the PHP buffers. This would have flushed the
buffers to your web server.
Now, flushing the PHP buffers to the web server could easily have filled
the web servers buffer. So now the web server has to flush its buffers
to the browser.
All of this takes time, also.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: PHP Optimization question
am 13.01.2008 17:34:34 von IanReardon
My sever is a dual core intel box, dedicated running CentOS and 1 gig
of ram. No other websites are hosted on this box
I have MySQL query cache of about 100M, which is being used quite a
bit when I check the cache hits
The php code is just HTML with inline php statements like, probably
about 75-100 lines
(this is just an example, my page uses CSS not tables)
To check the execution time I use a fucntion as follows
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
I record the start time, and end time, then print the delta
Any other suggestions would be appreciated, thank you!
On Jan 13, 9:13 am, Jerry Stuckle wrote:
> IanRear...@gmail.com wrote:
> > I'm trying to optimize a php project of mine and I'm running into some
> > problems.
>
> > Overall the page takes about .4-.5 seconds to render (just the code,
> > i'm recording the time at start and finish of execution) on a my dual
> > core server with nothing else running (other than httpd and mysqld)
>
> > I've optimized my queries, total mysql query time is about .1 to .12
> > seconds total.
>
> > For some reason the part of my php that takes the longest to execute
> > is a rather large section of html code with some echo $someVar; ?>
> > sprinkled in. There is no logic or functional calls, yet this block
> > of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
>
> > Can anyone recomend ways to find out where my php code is executing
> > slow?
>
> > Thank you
>
> How do you know it's taking that long for the PHP to execute? I
> wouldn't expect it to take very long to process the HTML code. You
> didn't show us what echo statements you had, but I wouldn't expect a few
> of those to take long, either.
>
> There can be a lot of other things involved. For instance, during this
> code, you may have filled the PHP buffers. This would have flushed the
> buffers to your web server.
>
> Now, flushing the PHP buffers to the web server could easily have filled
> the web servers buffer. So now the web server has to flush its buffers
> to the browser.
>
> All of this takes time, also.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Re: PHP Optimization question
am 13.01.2008 19:09:59 von seaside
On 13 Jan., 17:34, IanRear...@gmail.com wrote:
> I have MySQL query cache of about 100M, which is being used quite a
> bit when I check the cache hits
Could you provide the whole script. I don't see anything special which
would
force the web-app to answer slow yet.
The actual source might help.
Re: PHP Optimization question
am 13.01.2008 20:38:22 von Jeff North
On Sat, 12 Jan 2008 22:42:11 -0800 (PST), in comp.lang.php
IanReardon@gmail.com
<08d67142-ced8-4e16-a9dc-dc264f4ce749@f47g2000hsd.googlegroups.com>
wrote:
>| I'm trying to optimize a php project of mine and I'm running into some
>| problems.
>|
>| Overall the page takes about .4-.5 seconds to render (just the code,
>| i'm recording the time at start and finish of execution) on a my dual
>| core server with nothing else running (other than httpd and mysqld)
>|
>| I've optimized my queries, total mysql query time is about .1 to .12
>| seconds total.
>|
>| For some reason the part of my php that takes the longest to execute
>| is a rather large section of html code with some echo $someVar; ?>
>| sprinkled in. There is no logic or functional calls, yet this block
>| of code (maybe 50 lines of HTML, takes around .3 seconds to execute.
>|
>| Can anyone recomend ways to find out where my php code is executing
>| slow?
>|
>| Thank you
You're joking, right?
Have you stopped to think that it might not be the php code that is
slowing things down?
In another post you show a simple table layout.
Could it be your browser that is causing this 'bottleneck'?
The browser needs to :
read your generated code
parse it
create the DOM structure
render the table
No of the above happens until the tag is reached.
To test this out:
remove all html code from the page and just have your echo statements.
What is the timing?
-- ------------------------------------------------------------ -
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
-- ------------------------------------------------------------ -
Re: PHP Optimization question
am 15.01.2008 12:57:46 von Toby A Inkster
IanReardon wrote:
> Overall the page takes about .4-.5 seconds to render (just the code, i'm
> recording the time at start and finish of execution) on a my dual core
> server with nothing else running (other than httpd and mysqld)
Have you tried running your script from the command line? It may be that
the bottleneck is in Apache, not your script.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 15 days, 23:10.]
GPS & Cameras
http://tobyinkster.co.uk/blog/2008/01/14/gps-cameras/