number of include()s

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

IF I make a PHP script that uses varoius external function from include()ed files, does it make a significant difference how many includes() are used for these functions.

I would rather keep things separate for management of code, but I have heard that lots of include()s reduces performance. How significant is the performance change?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Unless you have thousands includes, I don't think you will notice any difference. Anyway, try to find a balance.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Thats what I thought. I didn't see why there would be much difference as the files are just plain text files but thought it would be best to ask before I jump in. It's gonna be about 4-5 includes I think.

Thanks for the help leo
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Since the server will open and read a new file for each include in the PHP, there is a little overhead. But it is just nothing. You are talking about 5 includes, don't worry about the overhead. I guess, for a good webserver you can use 30 includes without any problems.

I tried to measure the overhead once, I was building a site with more than 20 includes for each user hit. I used timers to see the build time of the file with includes against a single file (no includes). I don't remember any results of the tests, but I used includes in the site :)
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

_Leo_ wrote:
I used timers to see the build time of the file


well duh!!! Right, well that will be the solution to a different question I know I'm gonna have in a a week or two. Why don't I ever think of the easy way of doing stuff :lol:
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

hehehe :)
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

The way I usually do it is have an include.php file listing all the includes I need.

Some times the files get pretty hair raising interms of the number of include but I have never noticed any perfomance drops.

Another way to reduce the number of includes is to write code you can re-use across the entrie site ie:
instead of having an html page as the header and an html page as the footer write two funstions in one page that generate the header and footer code then echo the two results etc
  • Johan007
  • Guru
  • Guru
  • User avatar
  • Posts: 1080
  • Loc: Aldershot, UK

Post 3+ Months Ago

I am an ASP coder but its all the same thing... Includes have little effect on performance but you should keep to a small number just to manage it all eg: you page linked to page wrapper that links to header include, footer include and a global variable and db connection include.

I think people are confusing this with inline tags. ASP tag, <% …. %> and PHP is <%PHP …. %>, This approach is by far the easiest to implement at first and it leaves the HTML portions of the page in an easy to read and maintainable format…but its bad coding.

Fastest is to use a Response.Write without CRLFs but your view source will give you unformated HTML but this is better becuase there is less data to transfer ... checkout http://www.futuremovies.co.uk and view source. I use a variables to output into about 5 Response.Write 's . Don’t forget meta tags will need CRLFs for Inktomi to read them but this may not be the case nowdays.

A guide to enhancing ASP Part 1

aspemporium.com - Increasing the Execution Speed of Your ASP Programs
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Dude, the source code for that page is <b>huge</b>
You have saved 50% by formatting it all on to one line but 16k for what exactly? The page started off at 30Kb when i reformatted with whitespace. 30kb is what I aim for with all the graphics and external files included! You have 4-5kb of actual readable text and so that leaves 12Kb just for the layout.

You would do better to sort out your html, cut out all the crap (nested tables and spacer gifs etc) and get the page <i>layout</i> down to about 5-10kB with the whitespace still left in, then remove the whitespace if you are feeling really fanatical about size.

Sorry if that seems a bit harsh but on my pages that technique will save about 2kB most, so I shall not be worrying to much about it.


Rabid dog, do you meaqn you have a kind of nested include, like each page includes include.php and then include.php has:

Code: [ Select ]
include 'file.php';
include 'file2.php';
etc etc...
  1. include 'file.php';
  2. include 'file2.php';
  3. etc etc...

I wasn't too sure on that one.

I already started using a single php file for the head, footer and nav generation, but thanks for the tip. :wink:
  • Johan007
  • Guru
  • Guru
  • User avatar
  • Posts: 1080
  • Loc: Aldershot, UK

Post 3+ Months Ago

harsh yeah :D ... we are talking about Server side coding not my rushed HTML with little .css support. Nested tables are quicker to code sometimes when your site moves dynamically depending on what you set up in the user admin. Its not ideal but I thought it was worth the hit just to get the job done.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Hmm, I still would have gone for divs's with clear:both and floated images for most of your site. Chuck in a couple of margins and you're done. You did say that it was good because the amount of data transfered was smaller....

To be fair I as already thinking along the lines of having the whole page in a couple of variables and then outputting at the end. Strikes me as being more mangeable in the code as well.
  • Johan007
  • Guru
  • Guru
  • User avatar
  • Posts: 1080
  • Loc: Aldershot, UK

Post 3+ Months Ago

I never had the knowledge to use DIVs to that level or the time to learn. If it was a simple design then yes but I see it as far too complex of a task and not worth the effort.

Anyway back on topic…


rtm223 wrote:
To be fair I as already thinking along the lines of having the whole page in a couple of variables and then outputting at the end. Strikes me as being more mangeable in the code as well.


yeah I use "out" as the variable in the page function pageData() and server include the bellow "wrapper"

Code: [ Select ]
<!-- #Include virtual="/inc/navigation.asp" -->
<!-- #Include virtual="/inc/footer.asp" -->
<%
Response.Buffer = True

Dim out, icount

out = pageData()

Response.Write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""><html><head>" & vbCrLf & _
    "<title>" & strPageTitle & "</title>" & vbCrLf

            
Response.Write displayTop() 
Response.Write out
Response.Write displayFooter()

Response.Write "</body></html>"
%>
  1. <!-- #Include virtual="/inc/navigation.asp" -->
  2. <!-- #Include virtual="/inc/footer.asp" -->
  3. <%
  4. Response.Buffer = True
  5. Dim out, icount
  6. out = pageData()
  7. Response.Write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""><html><head>" & vbCrLf & _
  8.     "<title>" & strPageTitle & "</title>" & vbCrLf
  9.             
  10. Response.Write displayTop() 
  11. Response.Write out
  12. Response.Write displayFooter()
  13. Response.Write "</body></html>"
  14. %>


In the pageData() I use out = bla bla.. instead of Response.Write.
  • Johan007
  • Guru
  • Guru
  • User avatar
  • Posts: 1080
  • Loc: Aldershot, UK

Post 3+ Months Ago

rtm223 wrote:
then remove the white space if you are feeling really fanatical about size.


ahhh I see you don’t understand yet what I meant but you will do when you start coding using only 3 or 4 InLine tags. When you code In line less you don’t get character returns you have to add them in manually 20% more processor intensive in ASP. Instead you leave character returns out and get 10% speed increase (as well as making the HTML a tiny bit smaller to download). Its the same in PHP.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

ahhhh I do see where you are coming from now, it was this line that got me confused:

Quote:
will give you unformated HTML but this is better becuase there is less data to transfer ... checkout http://www.futuremovies.co.uk and view source
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

rtm223 wrote:

Rabid dog, do you meaqn you have a kind of nested include, like each page includes include.php and then include.php has:

Code: [ Select ]
include 'file.php';
include 'file2.php';
etc etc...
  1. include 'file.php';
  2. include 'file2.php';
  3. etc etc...

I wasn't too sure on that one.

I already started using a single php file for the head, footer and nav generation, but thanks for the tip. :wink:


rtm223 that would be correct! I just find I get less file not found errors. and it is easier to maintain. :wink:
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Instead of a head include, a footer include, and a nav include, I usually make one page template and have one switch that actually takes care of each page.

DB includes and what-not I can understand, but when you separate the header, footer, and nav you've just got more files to edit to take care of one single page than you would if you made one template with everything on it and made a "brain" switch for managing actual pages.

But that's just my method.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

gsv2com wrote:
Instead of a head include, a footer include, and a nav include, I usually make one page template and have one switch that actually takes care of each page.

DB includes and what-not I can understand, but when you separate the header, footer, and nav you've just got more files to edit to take care of one single page than you would if you made one template with everything on it and made a "brain" switch for managing actual pages.

But that's just my method.


I agree although i just have two functions ie printDoc($title, $body)
which returns a formatted XHTML string, the navigation and the body and one for the footer ie printFooter inside the same file :D

Post Information

  • Total Posts in this topic: 17 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.