Page 1 of 1

HTML and PHP Code

Posted: Wed Sep 28, 2005 10:31 am
by aka_eu
In one part of my code I have to generate a lot's of html form arranged in huge table. Sometimes I have about 50 lines with 2 forms inside each. I tryed different methods to output the html code but is too slow. From 2 to 4 secconds.

My code is something like this.

Code: Select all

QUERY1 = SELECT 1 made from 3 joined tables  // Time of the execution is very small 
for each line in query1 {
   OUTPUT HTML // A lot of html code with more that 10 php vars inside
   QUERY2 = SELECT 2 made from 2 joined tables // Time of the execution is very very small 
      OUTPUT HTML // SOME html code with more that 3 php vars inside
      for each line in query2{
         OUTPUT HTML// SOME html code with more that 2 php vars inside
     }
  OUTPUT HTML   //closing HTML forms,rows,etc..
}
What is the fastest method to use ?
1. echo "<table ....>$var1.....$var2.....";
2. echo "<table ....>".$var1."......".$var2.".....";
3. ?><table ....><?=$var1;?>.....<?=$var2;?>.....

Or should I use something different ?


If I will put on comments the OUTPUT HTML parts the execution time is less then : 0.05s .

Posted: Wed Sep 28, 2005 10:56 am
by feyd
why not test the various methods and find out for yourself and your particular instance?

Posted: Wed Sep 28, 2005 10:58 am
by alvinphp
Since you have a query in a loop you are calling that query multiple times. That is going to takes it toll. Also, if your output is large (ie a large table output) it will be slow no matter what. The different methods you mentioned are not going to make any noticable difference.

Posted: Wed Sep 28, 2005 11:00 am
by Buddha443556
Might want to turn on output buffering it may help with memory allocation.

Posted: Wed Sep 28, 2005 11:02 am
by Jenk
Just a quick one,

If you are going to use echo "<table>".$var."</table>" use single quotes (') and not doubles (") as double denotes that PHP should scan the string for variables/special chars, where as single denotes it is to be used literally.

Posted: Wed Sep 28, 2005 11:13 am
by aka_eu
alvinphp wrote:Also, if your output is large (ie a large table output) it will be slow no matter what. The different methods you mentioned are not going to make any noticable difference.
I made my self some tests and I didn't observed any noticable difference. So I'm still looking for a sollution.

Posted: Wed Sep 28, 2005 11:56 am
by Skara
That sounds like a solution to me in itself. If there's not much difference, hooray. :P

Just by guesswork, I would say that either
echo 'word '.$var.' word';
would be faster than
echo "word $var word";

In the first you tell it where the variable is. In the second, it has to find it.

I really don't know how the last one works. Anyone know if <?=$var?> calls the echo function or something?

Anyway,
echo 'word '.$var.' word';
echos text, then a variable, then a word.
word <?=$var?> word
just echos the one variable, so it seems that it might be faster still.

If you constantly switch back and forth between text and variables, though, it might be faster to just use an echo.


But, like I said, this is all pure guesswork. ;)

Posted: Wed Sep 28, 2005 11:56 am
by Buddha443556
Just for some ideas ... Performance

Re: HTML and PHP Code

Posted: Wed Sep 28, 2005 12:22 pm
by McGruff
aka_eu wrote:What is the fastest method to use ?
1. echo "<table ....>$var1.....$var2.....";
2. echo "<table ....>".$var1."......".$var2.".....";
3. ?><table ....><?=$var1;?>.....<?=$var2;?>.....
There won't be any measurable difference. If you want to investigate, try apache ab and the Xdebug profiler.

Apache ab is the bottom line. A 10% difference in a chunk of code which only takes up 1% of the total execution time is 10% of nothing.

See RulesOfOptimization

Posted: Mon Oct 03, 2005 3:56 am
by aka_eu
I can say that my code is optimized, and all I have to do.. is to get Zend Optimizer... or to use a Cache system. I'm not sure that the cache system can help me, because the informations are changing very very fast. I have to continue to study the Cache Pear package to see if that can help me. To cache just some parts.