Forum Moderators: coopster

Message Too Old, No Replies

Performance and Multiple Include User Functions

         

Net_Wizard

3:11 pm on Sep 28, 2003 (gmt 0)



Need advice from PHP Gurus...

I'm kind of curious as to what is the performace effect(memory, server load, etc..) of multiple includes, say 30-50 include call.

I'm trying to script in PHP where...

the public PHP page(index.php, etc..) would contain a single PHP include statement -> <? include("path_script.inc")?>

where "path_script.inc" would contain the path to a library of functions -> /path/include_lib.inc

where "include_lib.inc" would further contain all the major class and other functions. Meaning, this file would be the master include file.

I'm new to PHP but not new to programming. Correct me if I'm wrong but it is my understanding that this kind of structure would load all the functions regardless if they are needed or not by the calling page.

Say, index.php would need functions 1-5 and doesn't need the rest of the library of functions. Say, page2.php would need functions 1,2,6 and different function needs for each public php page.

How would this effect your server load and memory allocation? Anybody have experience with this kind of situation.

Or, how would you structure your scripts in such a way that the public php pages don't have to call several include to different location of your scripts for security reason and ease of management?

Any input please?

Thanks

jatar_k

5:24 pm on Sep 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



say 30-50 include call

seems like a lot but if you need it, you need it

I don't really understand the need to include path_script.inc and include_lib.inc if all path_script.inc is doing is to hgave the path to another file to include.

Here's the way I try to structure things.

I always have a config file which has to be included first.

Then I usually have a site wide include. These are the functions that are needed 99% of the time so they need to be included on every page.

I use include_once instead of include to be sure that libs aren't double included.

I then include in dividual libs, either, on each page or with a section based include for things needed there. I also just build my libs targetted to individual sections or related groups of processes.

How would this effect your server load and memory allocation?

there are no adverse effects because we benchmark everything and run multiple servers of our own that are real monsters. ;)

It does depend on your own individual setup. You also have always be aware of these things and, when designing and building, structure things accordingly. Would our system run on a smaller setup? No chance, but it shouldn't be put on a smaller setup either.

things to keep in mind

  • everything is seperated into individual tasks
  • functions need to be grouped as logically as possible (according to tasks)
  • keep the loading of unused functions to a minimum
  • remember that web software has core behavioural differences to classical software design
  • check everything on slower connections to truly recognize slow downs

    then all should be well

    I aslo don't name any of my files .lib or .inc, it's always .lib.php or .inc.php then code can never be viewed in a browser if someone happens to know a filename.

  • Net_Wizard

    7:59 pm on Sep 28, 2003 (gmt 0)



    I don't really understand the need to include path_script.inc and include_lib.inc if all path_script.inc is doing is to hgave the path to another file to include.

    There's a need to separate scripts from contents. Scripts would be located to a directory that is only known to the administrator.

    I then include in dividual libs, either, on each page or with a section based include for things needed there. I also just build my libs targetted to individual sections or related groups of processes.

    So, for example if a page would need 3 functions then in your page, you would have 3 <? include("file")?> and 3 function calls <? function()?>. Right? Unfortunately, I couldn't do that.

    I also don't name any of my files .lib or .inc, it's always .lib.php or .inc.php then code can never be viewed in a browser if someone happens to know a filename.

    I agree with you, I don't know what I'm thinking, so used to naming files according to their function. :)

    Thanks for the sound advice. I'll try to benchmark it and see if it has an adverse effect on a single server. Probably, I might end running it through an optimizer, hope not.

    Cheers

    jatar_k

    8:31 pm on Sep 28, 2003 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    So, for example if a page would need 3 functions then in your page, you would have 3 <? include("file")?> and 3 function calls <? function()?>.

    not really, probably poor explanation on my part, sry.

    say we have

    db_funcs.lib
    datetime.lib
    form.lib
    section2.lib
    section7.lib
    etc

    The functions within these libs are grouped by function, sometimes split into 2 libs if it helps processing.

    if there is no form I won't need the form.lib.
    if I'm not in section7 I won't need it's lib
    etc

    Seems to make perfect sense but sometimes there are different lib breakdowns that make sense when in a web environment than in an offline software application.

    I usually put all path information in the config script and then include from there. You may also see different performance impacts if you nest includes too much than if you just include them all right on the page.

    Net_Wizard

    1:36 pm on Sep 29, 2003 (gmt 0)



    Thanks and you are right that functions should be broken down to libs that are grouped according to their relative functions and just call that lib once.

    Appreciate your help and I'll see if I can streamline my include calls.

    Cheers

    jetboy_70

    2:20 pm on Sep 29, 2003 (gmt 0)

    10+ Year Member



    jatar_k's advice is the best in regards to extensions on your files, but you could add a .htaccess line to enable PHP parsing in files with other extensions, which would also protect them from prying eyes.

    AddType application/x-httpd-php .php .lib .inc

    Net_Wizard

    9:26 pm on Sep 30, 2003 (gmt 0)



    Hey, another good advice :)

    Thanks

    coopster

    12:31 pm on Oct 1, 2003 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    You may also choose to keep includes outside of the server (public) path.

    /
    ¦-cgi-bin
    ¦-files
    ¦-includes <------browsers can't get here
    ---first.inc
    ---second.inc
    ¦-logs
    ¦-www <-----------public area
    ---about.htm
    ---contact.htm
    ---index.php

    Net_Wizard

    10:55 pm on Oct 2, 2003 (gmt 0)



    Great idea. Thanks