SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Indifferent's Avatar
    Join Date
    Apr 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Choosing Caching Systems

    Which of the following would you say is the best system to use:

    1. "Advanced PHP Cache" ACP http://phprpms.sourceforge.net/apc
    2. eAccelerator http://eaccelerator.net/ or
    3. Memcached http://www.danga.com/memcached/
    4. Or maybe something else?

    I know people will say that it depends on the situation, but what gives the most features and speed out of the 3.

    Or how about in some senarios, which would be the best to use:

    1. A blog with regular content and an highly active forum.
    2. A portal type of system were users communicate with each other.

    How about for this website, sitepoint, what would be the best?
    What is used here?

    Any advice or tips or whatever would be appreciated.

    Thanks in Advance

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2007
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eAccelerator is what I use for local cache.

    Memcached is a more full blown data cache for databases. Probably overkill.

    1) & 2) Both are really database issues, both realtime meaning little caching outside of the database server will be advantageous. Editing the said databases config, data caches etc is what you should be looking into.

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You cannot compare these things and ask which is best. #1 and #2 are both, at the core, code caches. They store precompiled PHP code so it doesn't have to be compiled again next time the same script is run. Not a big difference between the two, but I use APC.

    Use APC or eAccelerator. Nobody should run PHP without an opcode cache. I can't imagine why one wasn't built into the PHP engine itself except as a way for Zend to make money selling their accelerator.

    Memcached is an object cache. It's for storing information, not code. You could use it with or without a code cache. You might store the results of a complex database query that doesn't need to be run often, for example.

    The best thing for your blog is a file cache, not any of these things. If it's so popular you really need to reduce its load, then generate static versions of all the pages and serve those instead of building them on each request. Update the cache only when your content changes.

  4. #4
    SitePoint Zealot GiorgosK's Avatar
    Join Date
    Jun 2007
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post

    The best thing for your blog is a file cache, not any of these things. If it's so popular you really need to reduce its load, then generate static versions of all the pages and serve those instead of building them on each request. Update the cache only when your content changes.
    Thanks Dan, exactly what I was in need of, great advice ...

    how do you suggest that we proceed with this ? is there a configuration on apache servers that does this automatically or is it usually a custom coded solution ? any pointers to a good tutorial ?

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    //check if the cache file already exists

    //generate a unique filename based on the REQUEST_URI to
    //implement this in a generic fashion

    if (file_exists('cache.html')) {

      
    // the output is already cached, so just
      // dump the file's contents to the browser
      
    readfile('cache.html');

    } else {

      
    // otherwise, the cache doesn't exist yet
      // so re-generate the content

      // turn on output buffering so your code's output
      // gets stored in the buffer instead of sent to the
      // browser
      
    ob_start();

      
    // here you can place the existing PHP and HTML
      // you want to cache

      // now, write the output you captured in the buffer
      // into the cache file
      
    $fp fopen('cache.html''w'); 
      
    fwrite($fpob_get_contents());
      
    fclose($fp);

      
    // and output the buffer's contents to the
      // browser as well
      
    ob_end_flush();


    If you have header and footer or some other template system already, then you could have this implemented across the entire site in minutes.

    There's probably a WordPress plugin for caching somewhere if that's what you're using... I'm not the type to go look, though. There are a couple pieces of my blog template that are separately cached to files and update when the cache is 5 minutes old (checking filemtime compared to current time)... just quickly coded into the theme.

  6. #6
    SitePoint Zealot GiorgosK's Avatar
    Join Date
    Jun 2007
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan thanks a lot for the code, I am going to try it out ...


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
  •