Forum Moderators: coopster

Message Too Old, No Replies

what is the best way to 'include' template content

         

cosmonaut

7:06 pm on Aug 7, 2014 (gmt 0)

10+ Year Member



Hi all,

I have been building sites for years now... but just recently my hosting company flagged up an issue of too much resource useage in my account. I didn't even know I had a set limit.

They provide me a graph of total resource useage, and totals for each domain, but no breakdown by file, so it's hard to know exactly which bits of code are causing the most useage without a lot of testing. I managed to block a whole lot of bots which has solved the problem for now, but ultimately I want to use the sleekest methods where possible.

Anyway, I'm making a new site, and I will have templates for the header footer etc.

My favourite way of doing this is with a php file full of functions

$page -> header();

But I could always do an include

include("/home/mysite/public_html/includes/header.php");


My question is: which method uses the lowest resources, assuming they both create exactly the same header? Is there a significant difference once you get a lot of traffic?

Thanks all!

penders

2:23 pm on Aug 8, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To be honest I can't see a great difference between those methods that would greatly affect "resources". In fact, from what you have given, there is potentially no difference - for all we know your header() method is simply doing an include? What are you doing inside your header() method?

Is your "template" just a PHP file, in which you do something like this?

<?=$page->header()?>


What exactly does your host mean by "resources"? Memory, CPU usage, ...? And what is a typical figure for "total resource usage"?

How many objects are you instantiating during a typical page request? How much memory does a typical page request consume? How long does it take the server to generate a typical page?

cosmonaut

4:19 pm on Aug 8, 2014 (gmt 0)

10+ Year Member



Hi, and thanks for your answer

yes, it's all very vague - the "resources" seems to be in some arbitrary units; a mix of memory and cpu useage and maybe other processes.

Here is their description of it all
[site5.com...]

It's the principle I'm interested in - assume the header() method or the include were both echoing the same html

penders

7:07 pm on Aug 8, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here is their description of it all


Blimey, that's quite a lot of restrictive restrictions! You could quite easily exceed some of those limits on a moderately busy website, almost regardless of how your site is coded. Are your sites "busy"?

("Unlimited disk space / bandwidth" - many of those "restrictions" will indirectly limit both disk space and bandwidth.)

It's the principle I'm interested in - assume the header() method or the include were both echoing the same html


Well, as mentioned, the implementation can affect this. However, "in principle" there is little to separate them. Code the way it is easier to develop/maintain.