Page 1 of 1

simple question concerning preformance

Posted: Thu May 22, 2003 7:54 am
by r337ard
is it faster to say, have an php file with a list of functions in it that call outside files to read in data when needed.
ie:

Code: Select all

function one(){
   readfile("./one.php");
}

function two(){
   readfile("./two.php");
}
as opposed to having a huge php file with all the code you would want run, for pretty well all situations in it.
ie:

Code: Select all

function one(){
  print "This is the first section";
   if (empty($_GET['var'])) {
        print "no info here, sorry";} else {
        print "$var is the info here";};
   print "and so on and so on";
}
function two(){
   print "This is the second section";
   if (empty($_GET['var'])){
        print "oops";} else {
        print "$var is the info here";};
   print "and so and so:;
}

:oops: it may be obvious, im just curious. iv been using readfiles and includes to keep the code clean and easy to work with. but im not sure if its going to be faster or slower in the long run doing it that way. if each section is say, 30-200 lines of code.

Posted: Thu May 22, 2003 8:42 am
by ckuipers
I'm not sure how the 'readfile' works but when you work with 'include', PHP actually replaces the 'include' statement with the full text in the include file.
It therefore doesn't improve your performance to use includes although it does make your files easier to read and more manageable.
I use the includes to add functions that are stored seperately to the pages.

Posted: Thu May 22, 2003 9:28 am
by r337ard
mmm, thank you, thats exactly what i wanted to know :)

readfile just reads the contents of a file, as far as i understand it works more or less exactly like include, but works in places includes dont.

i was just afraid it was going to end up being a big preformance hit as the site grew (especially if the userbase grows).

thank you

Re: simple question concerning preformance

Posted: Thu May 22, 2003 11:27 am
by gyardleydn
So you use

Code: Select all

function one(){
   readfile("./one.php");
}
to avoid looking in the include path? It seems to me that the include path will only be look at if the file is not found locally, so why do you do this :?:

Just curious


edit:
Ok, after looking it up, include path is always used but ".;" or ".:" is usually inserted at the start of the path because " Using a . in the include path allows for relative includes as it means the current directory".

But I'm still curious

Posted: Fri May 23, 2003 10:13 am
by r337ard
mm, i just wrote it as a quick example of the code to represent what i was doing. i keep most files that get included in a /includes/ directory. i use include() for things that are nessicary each and every time the page is loaded, and readfile() for information that only needs to be included sometimes (like in an if statement, or a function). the only files that remain in the same directory as the index file, are the things that get included every time the page is loaded (header information, and the layout of the page).

im not sure this is the proper way of doing this, but it is how iv been doing it thus far. i hope this clears it up :)

edit: if it wern't a quick podge it would read:

Code: Select all

function one(){
   readfile("./includes/one.php");
}

function two(){
   readfile("./includes/two.php");
}