SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to create server cache for my website

    We have developed one website site. Now some user are using this site, so i plan to create server cache for some page in the site's so send some tips or ways to create simply without problem.
    Last edited by Mittineague; Jun 21, 2013 at 10:08. Reason: removing unnecessary link

  2. #2
    SitePoint Member
    Join Date
    Sep 2013
    Location
    Chennai
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am working in PHP and I think ob_start() function and ob_end_flash function will help you to create you server cache for your website.
    Here is the example coding:

    <?php
    // Define path and name of cached file
    $cachefile = 'cache/'.date('M-d-Y').'.php';
    // How long to keep cache file?
    $cachetime = 18000;
    //Is cache file still fresh? If so, serve it.
    if (file_exists($cachefile) && time() - $cachetime <
    filemtime($cachefile))
    {
    include($cachefile);
    exit;
    }
    // if no file or too old, render and capture HTML page.
    ob_start();
    ?>

    <html>
    Webpage content in here
    </html>

    <?php
    // Save the cached content to a file
    $fp = fopen($cachefile, 'w');
    fwrite($fp, ob_get_contents());
    fclose($fp);
    // Send browser output
    ob_end_flush();
    ?>


Tags for this Thread

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
  •