PHP Optimization question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to optimize a php project of mine and I'm running into some

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

Thank you

Re: PHP Optimization question

On Jan 12, 10:42 pm, wrote:
Quoted text here. Click to load it

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

Quoted text here. Click to load it

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


Re: PHP Optimization question

On 13 Jan., 07:42, wrote:

Quoted text here. Click to load it

Although mySQL takes just a few seconds, did you use an index for
in WHERE clauses?

Additionally, MySQL disables its cache by default. You need to enable
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 wrote:
Quoted text here. Click to load it

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.

Re: PHP Optimization question

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)
    <td><? echo $someVar; ?></td>

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!

Quoted text here. Click to load it

Re: PHP Optimization question

On 13 Jan., 17:34, wrote:

Quoted text here. Click to load it

Could you provide the whole script. I don't see anything special which
force the web-app to answer slow yet.

The actual source might help.

Re: PHP Optimization question

On Sat, 12 Jan 2008 22:42:11 -0800 (PST), in comp.lang.php

Quoted text here. Click to load it

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 </table> tag is reached.

To test this out:
remove all html code from the page and just have your echo statements.
What is the timing?
-- -------------------------------------------------------------  : Remove your pants to reply
-- -------------------------------------------------------------

Re: PHP Optimization question

IanReardon wrote:

Quoted text here. Click to load it

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, up 15 days, 23:10.]

                               GPS & Cameras

Site Timeline