page load times

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

page load times

Post 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...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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)
User avatar
AnarKy
Forum Contributor
Posts: 119
Joined: Tue Nov 02, 2004 1:49 am
Location: South Africa

Is it?

Post 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....
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Maybe the html is not being processed but whether it displays or not is being controlled by PHP.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
Post Reply