homepage Welcome to WebmasterWorld Guest from 50.19.206.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Multiple Includes vs. Multiple Functions
In PHP, which requires more processing time?
tlhmh1




msg:1291491
 6:03 pm on Sep 25, 2002 (gmt 0)

In order to simplify code across many pages, I, like many people, have always used includes for the header, footer, and menu bar. I'm wondering, however, if the page would be served faster if I were to only have one include and use three functions (all of which are defined in the one included file) to deliver the header, footer, and menu bar.

For example:

FILE #1
--------------
<?php
include "header.php";
include "menu.php";
?>

CONTENT HERE

<?php
include "footer.php";
?>
--------------

or

FILE #2
--------------
<?php
include "master.php";
header();
menu();
?>

CONTENT HERE

<?php
footer();
?>
--------------

In other words, does it take the server longer to request 3 files, or request 1 file and call 3 functions?

 

jatar_k




msg:1291492
 7:07 pm on Sep 25, 2002 (gmt 0)

Have you tried the two seperate approaches? If you aren't returning a great amount of data I doubt there would be any difference. It would also have a large amount to do with what you are including and how any functions in the included files are coded.

Are you having problems with speed on you present setup?

tlhmh1




msg:1291493
 7:24 pm on Sep 25, 2002 (gmt 0)

No problems. Just always looking for ways to make things faster.

I haven't tested it, and really wouldn't know how to measure it.

I'm also starting to develop a new site and I want to do it right from the beginning.

andreasfriedrich




msg:1291494
 7:46 pm on Sep 25, 2002 (gmt 0)

really wouldn't know how to measure it

There is nothing mysterious about benchmarking. If you know how to time how long it takes you to get from home to work you know how to benchmark.

1. Get current time.
2. Do something.
3. Get current time.
4. Calculate difference between 3 and 1.

In php terms do something like this:

function getmicrotime($t) { 
list($usec, $sec) = explode(" ",$t);
return ((float)$usec + (float)$sec);
}

$start = microtime(); 
// do your includes here
$end = microtime();

$diff = getmicrotime($end) - getmicrotime($start);

To increase accuracy and if runtime is very low put the code in a loop and run it 100 times. Also remember that the runtime depends on the load of your server and a lot of other factors you need to take into consideration.

Andreas

jatar_k




msg:1291495
 7:48 pm on Sep 25, 2002 (gmt 0)

perfect description, thanks andreas.

tlhmh1




msg:1291496
 7:51 pm on Sep 25, 2002 (gmt 0)

That's interesting. I just may try that. Thanks!

NameNick




msg:1291497
 8:34 pm on Sep 25, 2002 (gmt 0)

Andreas,

I use a similar code and I have noticed that on my WAMP the run time is not accurate. It differs too much. On the webserver it runs perfect. I heard from other users that they have got the same problem.

NN

ergophobe




msg:1291498
 11:34 pm on Sep 25, 2002 (gmt 0)

You can benchmark with microtime as Andreas explained, or with Apache Bench, which only will allow you to measure the whole page, but it will allow you to measure more accurately how long it takes for the entire page. There's a good article on how to use both at

[zend.com...]

If you're really in a techie mood, see also

[phplens.com...]

and

[php.weblogs.com...]

Tom

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved