Page 1 of 1

page load times

Posted: Fri Jul 29, 2005 9:53 am
by Skittlewidth
Ok, so my massive ASP :evil: book arrived at my office today so naturally I began reading it. About 3 chapters in (yawn!) it says the following:
Each block of ASP code, enclosed in a pair of <% ... %> tags requires another call to the ASP DLL, meaning that the more times you use <% ...%> on a page the longer your code will take to execute.
Is this true in PHP? I'm guessing it is, but having read a couple of books and many tutorials and having spent several years using the forums I've never come across a warning similar to this before. Just wondering...

Posted: Fri Jul 29, 2005 9:57 am
by onion2k
Yes it's true. It's not as bad in PHP as it is an ASP though.

Even in ASP it's not that bad.. if you're worried about that level of optimisation then you need to stop coding and go down the pub.

Posted: Fri Jul 29, 2005 10:02 am
by Skittlewidth
onion2k wrote: if you're worried about that level of optimisation then you need to stop coding and go down the pub.
Hehe, actually I've only just come back from there.

No, I'm not worried about it but the stupid book harped on about it as if it was a really critical issue for the rest of the chapter. Anyway, all this learning has made me sleepy. Time for a nap. Then home time. 8)

Is it?

Posted: Fri Jul 29, 2005 10:04 am
by AnarKy
Hi,

I Don't think that this is the case at all...
(i.e. that the more <?... ?> causes greater delay)

:idea: My logic makes me believe that if you have fewer of <?.. ?>,
the you will have more code between the <?... ?> and thus
more code will have to be processed - which will also decrease
performance.

So then, is it just a question of whether the making of extra calls
because of the extra <?... ?> is less efficient than having more code
between the <?... ?> :?:

(This assumes that you still want the same stuff on the page.)
Please comment....

Posted: Fri Jul 29, 2005 10:14 am
by Skittlewidth
No, I think the basic logic is that when the server runs through the php page, it looks for the opening <?php tag and then the PHP.dll or equivalent processes all of the code until the ?> then deals with the html, and then if it comes to another block of code it has to refer it to PHP the dll a second time and so on. If its all between one pair of tags then it will deal with it in the first go. Of course it isn't always practical to code that way...

Thats really simplified tho, its probably not an accurate way of explaining things

Posted: Fri Jul 29, 2005 5:09 pm
by bokehman
It is very simplistic to think of the html sections as not being enterpreted by php and just sent to the client but it is not true. For example if all html code was sent directly to the browser the following would not work, but it does.

Code: Select all

if(something){
?>

<html><section>

<?php
}else{
?>

<html><section>

<?php
}

Posted: Fri Jul 29, 2005 9:05 pm
by feyd
bokehman wrote:It is very simplistic to think of the html sections as not being enterpreted by php and just sent to the client but it is not true. For example if all html code was sent directly to the browser the following would not work, but it does.

Code: Select all

if(something){
?>

<html><section>

<?php
}else{
?>

<html><section>

<?php
}
The HTML sections aren't being processed by php, the code you placed around them is. PHP completely ignores code inside blocks that aren't going to be evaluated. Hence why we can magically make a function exist in the middle of a script, or check if a function is defined elsewhere and include (or not) something...

Posted: Sat Jul 30, 2005 3:58 am
by bokehman
Maybe the html is not being processed but whether it displays or not is being controlled by PHP.

Posted: Sun Jul 31, 2005 5:51 am
by malcolmboston
somewhat "off-topic" but hey, i was up for that award anyway 8O

it is "my personal opinion / preference" that HTML contained within PHP, whether it follows a logical structure and is only printed under certain circumstances, that all HTML contained should not be escaped from within PHP, this is not because of parse times, i have done massive operations with surprising speed due to PHP's pure awesome'ness i do it purel for readability issues, ok sure you have to add a \ before " (addslashes())but it just seems much more logical to me that HTML produced by PHP should be contained in it.

my $0.02

remember, readability is as important as the code

Posted: Sun Jul 31, 2005 6:18 am
by bokehman
I agree! At the moment I have 5 domains running php and not one page contains an HTML section. Even my includes don't contain html sections. Instead they contain functions with the html inside in heredoc syntax. That way I can have all my includes in one file and call them like this.

Code: Select all

require_once('includes.php');
top_of_the_page($arg1, $arg2, $arg3, $arg4, $arg5);
//unique section here
bottom_of_the_page();
The heredoc syntax is much more comforable and allows variables to be inserted anywhere without any additional changes.