Welcome to WebmasterWorld Guest from 54.242.63.214

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple Includes vs. Multiple Functions

In PHP, which requires more processing time?

     

tlhmh1

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

10+ Year Member



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

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



perfect description, thanks andreas.

tlhmh1

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

10+ Year Member



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

NameNick

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

10+ Year Member



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

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

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month