Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Your thoughts on include()

    I'm wondering if it's efficient processing wise to have large includes files attached to pages. For example, I have this php include file that it all it has are custom string functions. Now, some pages in my apps use most of these functions, while others use only a few, and some use just one. For the pages that use only a few of these functions of this include file, is it worth including that include file? Is it better to just copy that function needed from the include file and put it in the page and don't include the file?

    Wondering what you guys think is best. By the way, these string functions are related, so I don't want to split them apart. There's still quite a few of them, and I'm worried about processing time.

    Thanks!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do you have a processing timer on your page? It's normally a good idea to keep a track of this in case it starts getting too big and you need to trim it down a tad.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,081
    Thanks
    11
    Thanked 99 Times in 97 Posts
    depends who you ask ..

    ask a JAVA head and they will tell you to include everything (ok they would be JAVA clases but you know what I mean) as its preferable to have all your code in one place for readability and fefactoring , e.g .you only ever change the scripts in your 1 include/class file instead of finding all the scripts where you used function 'x' and updating those (eg you may have found a better way to implement function 'x')

    Of course JAVA is compiled (nearly anyway) and after it's run once, there is no need to keep reinterpreting any included class definitions and the overhead is minimal.

    PHP is interpreted, so unless you are employing a low-level cache (Zend Cache etc) your includes get parsed each and every page request, which on a busy page can make a difference.

    There are $x ways to get around this from the simple 'dont worry about it', which is actually fine in many cases, to utilising a cache , to simply being happy to do a bit of refactoring now and again, to weird and wonderful code generators which are useful only if you develop within a custom framework.

    Often the biggest resource saver can be to look at your output and see what can be pre-`compiled`(to HTML) , eg , you have a database full of data that eventually gets parsed to a HTML table , all the functionality required to do that can be quite an overhead if loaded at runtime , often the chances are that the data only changes in that table once for every 1000 page views .. in that case you could build your HTML table and include it as a static file , whenever the database data changes you rebuild the include , etc.

    how big are your includes ? if they total say 100kb+ then I would start thinking about my options , else not worry too much about it.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •