SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server caching for include() and require() files?

    Hi folks,

    This has a great deal of pertinence for the way I'm building an application, so this forum seemed the most appropriate.

    For example, say I have a 100KB containing only variables (for the sake of this question, there's a whole lot of them!). In order to access this file in my code, I need to include() or require() it in my pages, of course. My question is, does PHP use some sort of caching mechanism on the server to re-load these files into memory quicker the second time it's asked for? Or is it loaded every time?

    What if the file is half a MB? Same thing?

    My follow up question is, if there's no caching going on, would it be quicker to pull the values from the file and store them in sessions? (Or should I just be doing some empirical testing...?)

    Thanks!
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  2. #2
    SitePoint Addict Mastodont's Avatar
    Join Date
    Mar 2007
    Location
    Czech Republic
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Implicit storage for sessions are files, so you gain nothing :-)

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Each time you include a file, it's loaded, parsed and interpreted. You can save the first two steps by using an opcode cache, such as APC.

  4. #4
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you could do is write a simple script to go over all your files and insert the literal script in the places where you have a require() or include() statement. That way you could save some of the IO overhead that is inherent to those statements.
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  5. #5
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before doing any of this, you need to do the appropriate testing to see if it's actually a bottleneck or not.

    In my experience, it's highly unlikely.

  6. #6
    SitePoint Member
    Join Date
    May 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Viflux View Post
    Before doing any of this, you need to do the appropriate testing to see if it's actually a bottleneck or not.

    In my experience, it's highly unlikely.
    How do you set up such a test? How do you simulate the load of the production server? I can read the same file on my development server a thousand times without actually reading it from the hard drive because it's sitting in a memory cache which would not give me a very accurate picture when looking for a hardware bottleneck ... would it? Is there a way around this? I'm hesitant to test on the production server at all let alone during peak traffic when it would count.

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > How do you simulate the load of the production server?

    Use a benchmarking tool, there are several to choose from

  8. #8
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://pecl.php.net/package/APC

    apc above is an opcode cache, and greatly (order of magnitude by my tests) improves php's performance as scripts are cached

    also apc allows you to store variables in it which is highly usefull, for example my framework has ability to cache application wide and module wide settings files and also l10n translation files into APC's memory storage on the first page load with quite a noticable improvement following


    but i run and control my own servers with latest php & apc + mysql + lighttpd/nginx so i dont think your average shared host would have APC installed

    but apc is going to be added to the core of php as of php6

    i think APC is one of the most important extensions for php and its being coded by core php developers


Bookmarks

Posting Permissions

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