SitePoint Sponsor |
|
User Tag List
Results 1 to 15 of 15
Thread: PHP and HTML performance issue
-
Aug 20, 2001, 01:10 #1
- Join Date
- May 2000
- Location
- Bangkok,Thailand
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP and HTML performance issue
Hiya,
When writing ASP pages, there is a marked improvement in performance if you minimise the switch between vb script and HTML by using response.write to echo the HTML code and to skip using the <%=whatever%> shortcuts.
What I am wondering is does the same hold for PHP? If instead of jumping in and out of PHP code in a page of HTML I coded the whole lot in PHP would there be an improvement in performance?
Much of the HTML could be run in functions (eg open and closeing tables springs to mind) of just echo using echo, print, printf etc.
Does anyone have any opinions on this, or any references to benchmark sites I can take a look at?
Thanks in advance.
Stuarthttp://www.travelfish.org
-
Aug 20, 2001, 02:39 #2
- Join Date
- Feb 2001
- Location
- New Zealand
- Posts
- 516
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There have been some benchmark's run by members here, and if my memory serves me correct the general concensus was that it was slightly faster to jump in and out.
There are others somewhere, but you could use robo's code on this page to test it for yourself:
http://www.sitepointforums.com/showt...threadid=27124Oh no! the coots are eating my nodes!
-
Aug 20, 2001, 08:34 #3
- Join Date
- Apr 2001
- Location
- Des Moines, IA
- Posts
- 346
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't feel the slight performance gain is worth it though. Jumping in and out makes the code hard to read, not to mention in encourages sloppy code.
-
Aug 20, 2001, 16:48 #4
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i think it makes it easy to read. but that's just me...
- Matt** Ignore old signature for now... **
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
-
Aug 20, 2001, 23:57 #5
- Join Date
- Feb 2001
- Location
- New Zealand
- Posts
- 516
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
To me a 2000 line PHP file with like:
echo '<html>';
etc, all the way through looks ugly, but I suppose that is why I use phplib's template class a lot, and functions where necessary.Oh no! the coots are eating my nodes!
-
Aug 21, 2001, 00:15 #6
- Join Date
- Dec 2000
- Location
- Idaho, USA
- Posts
- 452
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP runs faster when you run as much echoing as possible OUT of the realm where PHP will have to echo it out. It compiles the PHP code, then runs it, not running as it goes.
It makes work, especially when you're using a large number of tables, fast to code when you can just jump out of the scripting engine, dump it, then go back to the processing engine.... I just use <?=$var?> an awful lot
So for example:
PHP Code:<html>
<head>
<title><?=$title?></title>
</head>
<body background="<?=$image?>">
<table border="<?=$border?>">
<?php
$i = 0;
while($i < 50){
if(($i % 2) == 0){
$bgcolor = "red";
} else {
$bgcolor = "green";
}
?>
<tr bgcolor="<?=$bgcolor?>"><td><?=$i?></td></tr>
<?php
$i++
}
?>
</table>
</body>
</html>
PHP Code:echo("<html>
<head>
<title>$title</title>
</head>
<body background=\"$image\">
<table border=\"$border\">");
$i = 0;
while($i < 50){
if(($i % 2) == 0){
$bgcolor = "red";
} else {
$bgcolor = "green";
}
echo("<tr bgcolor=\"$bgcolor\"><td>$i</td></tr>");
$i++
}
echo("</table>
</body>
</html>");
?>
Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services
-
Aug 21, 2001, 00:30 #7
- Join Date
- May 2000
- Location
- Bangkok,Thailand
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
interesting
I find what you say interesting as it is almost exactly the opposite to the case with ASP where removing the short-cuts <%=whatever%> and running the response.writes together is definetely faster. In some cases yielding as much as a 50% improvement in speed (including moving to stored procedures) and about 20% without SP's.
It seems odd, as you'd assume that asp and php are effectivly doing and working in the same way.
Thanks anyway
shttp://www.travelfish.org
-
Aug 21, 2001, 01:14 #8
- Join Date
- Feb 2001
- Location
- New Zealand
- Posts
- 516
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well I could say that is because ASP su....
but then, I know the truth hurts some people.Oh no! the coots are eating my nodes!
-
Aug 21, 2001, 10:00 #9
- Join Date
- Dec 2000
- Location
- Idaho, USA
- Posts
- 452
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actually ASP is useful for enterprise level development, and it's what many large companies use, so obviously it does what they want it to.
PHP is a VERY loosly typed language, which is cool for us because we can get the same job with several different approaches. However, ASP teaches the programmer to code tighter, and therefore produces faster code. ASP is just DIFFERENT than PHP, and I, myself, sue them for DIFFERENT uses. Like just recently Exbabylon had to integrate a customer login with a regional ISP's program. Guess what? It was on win2K and MS SQL... fun huh? not really. I could've done it in PHP, sure, but ASP was so simple, fast, efficient....
Oh, and the one advantage PHP has is Zend.Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services
-
Aug 21, 2001, 15:51 #10
- Join Date
- Aug 2000
- Location
- Houston, TX, USA
- Posts
- 6,455
- Mentioned
- 11 Post(s)
- Tagged
- 0 Thread(s)
I like exiting out of the PHP to print certain HTML things that I need to do. Like this:
PHP Code:<?
$color = "red";
if($color == "red")
{
?>
<HTML>
<HEAD>
<TITLE>Red</TITLE>
</HEAD>
<BODY BGCOLOR="red">
RED PAGE
</BODY>
</HTML>
<?
}
else
{
?>
<HTML>
<HEAD>
<TITLE>White</TITLE>
</HEAD>
<BODY BGCOLOR="white">
WHITE PAGE
</BODY>
</HTML>
<?
}
?>ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
-
Aug 21, 2001, 21:28 #11
- Join Date
- Feb 2001
- Location
- New Zealand
- Posts
- 516
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Whoops, I think when I started that word with two letters you thought I was going to say something derogatory and bad about ASP
Instead I was leaving it open so that you could fill it in with anything you liked, I was thinking of two examples:
...because ASP su*** PHP's butt // makes asp sound good in a twisted way
and
...because ASP su*** // makes asp sound bad
Believe what you will, I'm not entering or starting a debate.Oh no! the coots are eating my nodes!
-
Aug 21, 2001, 21:40 #12
- Join Date
- Jun 2001
- Location
- Oklahoma
- Posts
- 3,392
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No one really seems to have answered the performance issues of jumping in and out of the coding very well, as was the primary purpose of this thread.
Answering whether jumping in and out of PHP code has an performance effects: it does slow down performance a little bit everytime you switch between <?php ?> and HTML coding.
The reason being that each time the PHP script begins anew, the PHP parser has to re-initialize to execute that coding -- which in turn causes more overhead and a slight increase in server processes.
So generally it is fine, but if you have an enourmouse script in which you exit and re-enter the PHP coding tags many times, it's going to have a negative effect on your performance because the PHP parser engine has to initialize, un-load, re-initialize, un-load, and so on and so forth.
So, unless you're dealing with a really small file, you're best bet is to keep the number of switches between your PHP coding and your HTML coding at a minimum.
Happy coding!Colin Anderson
Ambition is a poor excuse for those without
sense enough to be lazy.
-
Aug 21, 2001, 21:47 #13
- Join Date
- May 2000
- Location
- Bangkok,Thailand
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thankyou
To timnz, Most of my *fun* work is with php/mysql, most of my *paid* work is with asp/sql7/2000 - hence the question.
To Aes, Yes, that was what I was looking for. I was intrigued about this issue as there has been MUCH written about it with regard to ASP, but precious little from a PHP viewpoint
Thanks
stuarthttp://www.travelfish.org
-
Aug 21, 2001, 21:49 #14
- Join Date
- Feb 2001
- Location
- New Zealand
- Posts
- 516
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Aes, your wisdom seems to be different from that of exbabylon's.
And for me, when I ran a small "benchmark" it was faster jumping in and out of PHP than echo'ing it out, although I acknowledge that this could be drastically changed due to different environmental conditions, and a much larger file than the one I tested with.Oh no! the coots are eating my nodes!
-
Aug 21, 2001, 22:46 #15
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by Aes
The reason being that each time the PHP script begins anew, the PHP parser has to re-initialize to execute that coding -- which in turn causes more overhead and a slight increase in server processes.
So generally it is fine, but if you have an enourmouse script in which you exit and re-enter the PHP coding tags many times, it's going to have a negative effect on your performance because the PHP parser engine has to initialize, un-load, re-initialize, un-load, and so on and so forth.
ck :: bringing chris to the masses.
Bookmarks