What happens when a user accesses a page that calls multiple includes/classes?

Discussion in 'PHP' started by AntelopeSalad, Dec 12, 2006.

  1. #1
    I'm confused at how this all works together, as I just started really programming in PHP the other day.

    Example:

    Say you have 3 physical files.

    File #1: clsDatabase
    File #2: clsValidation
    File #3: clsProcessOutput

    Inside each file you have multiple classes.

    clsDatabase
    Class #1: cDatabaseConnect
    Class #2: cDatabaseFunctions
    Class #3: cDatabaseInstall

    clsValidation
    ...You get the idea.

    clsProcessOutput
    ...You get the idea.

    Inside of each class you have multiple functions. There's no need to list them. This is the basics of OOP, yes? I'm a little familiar with the OOP concept from working with c# for quite a bit.

    Then on each of my pages that use the classes (for instance, processing a new user), I include the files that contain classes I'm using in that page.

    Like If I need to connect, validate, and process output I would be including all 3 files. Then I setup my objects, and do what need I to do, cool.

    Here's the part I'm not grasping. Right now my files are pretty small because this is my first project (a light weight custom CMS). I've noticed other CMS' are filled with TONS of "crap". Upwards of 1 meg worth of just raw code.

    What's happening in the background when the user accesses one of these pages? Say they goto a sign up page, and fill it out.

    Boom, they just triggered an event that's going to require the server to load a page that's requiring 3 class files. Then all the code is going to get ran, and finally output something to the user (success, or failure).

    I'm assuming this all happening on the server right, because PHP is a server-side language? The user isn't transfering any of the code that's getting executed on the server. They only need to download the presentation page?

    Example:

    Say I have 50 classes now, and 30 different files. If I wrote some crazy page that accesses all of those files, but only outputs "hi", it should load for them instantly right?

    Instantly as in, as soon as the server processes all the stuff that needs to be done.

    That leads to question #2. I'm a super neat freak (or try to be :D) when it comes to coding. I like keeping things organized for humans not machines. This results in a lot of very small classes or files.

    To me it's easier to manage a directory of 10 folders, each containing 1 or 2 files, which then each contain a few classes. Rather than have 1 or 2 files that each have 20 classes.

    Also I like that idea of separating because there's no reason to include a 90kb file where you're only going to be using 1x 6 line function.

    For pure performance, is the "separating for human readability" just as fast as clumping it all together? It's a hard concept to grasp because in regular (pre-compiled) apps it all gets converted to machine code by the compiler, so how you literally manage your source does not effect the speed of the application.
     
    AntelopeSalad, Dec 12, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    The server will have to process all of the code on all of the files, but that doesn't get sent to the user. If you have 500Kb of code, then user doesn't have to wait for 500Kb of crap to transfer to their browser. The user receives only what is output to them, but they will have to wait for the server to process everything first.

    This depends on how your actual scripts interact with each other. If you can include and call specific classes and functions when you need, then it will be faster to use multiple files. If you need every class that you have all the time, then calling them all from seperate files will be slower. Either way, I don't think that there will be a huge difference in speed as long as you are using stardard include / require operators to get the data.
     
    jestep, Dec 12, 2006 IP