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...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.
page load times
Moderator: General Moderators
- Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
page load times
Ok, so my massive ASP
book arrived at my office today so naturally I began reading it. About 3 chapters in (yawn!) it says the following:
- Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
Hehe, actually I've only just come back from there.onion2k wrote: if you're worried about that level of optimisation then you need to stop coding and go down the pub.
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.
Is it?
Hi,
I Don't think that this is the case at all...
(i.e. that the more <?... ?> causes greater delay)
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....
I Don't think that this is the case at all...
(i.e. that the more <?... ?> causes greater delay)
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....
- Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
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
Thats really simplified tho, its probably not an accurate way of explaining things
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
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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...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 }
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
somewhat "off-topic" but hey, i was up for that award anyway
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
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
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.
The heredoc syntax is much more comforable and allows variables to be inserted anywhere without any additional changes.
Code: Select all
require_once('includes.php');
top_of_the_page($arg1, $arg2, $arg3, $arg4, $arg5);
//unique section here
bottom_of_the_page();