1

I am using PHP Simple HTML DOM Parser and using $html->load_file

include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('https://www.google.com/finance?q=goog');

the link below demonstrates a method to force caching of the content. I need to retrieve pages where the content changes depending on the last part of the url. Is it possible to modify the code below to force caching, for example, if I retrieve the following pages:

google.com/finance?q=goog

google.com/finance?q=wwwfx

google.com/finance?q=vigrx

Can I cache each one of those pages until the end of the session because I will need the page content repeatedly.

Caching PHP Simple HTML DOM Parser

function cache_get_contents($url, $offset = 600, $override = false) {
    $file = '/tmp/file_cache_' . md5($url);
    if (!$override && file_exists($file) && filemtime($file) > time() - $offset)
        return file_get_contents($file);

    $contents = file_get_contents($url);
    if ($contents === false)
        return false;

    file_put_contents($file, $contents);
    return $contents;
}
1
  • This is a lazy mans cache. Look into memcached. Or write code that looks at how old the file is and have it update the contents after n hours. Commented Mar 7, 2015 at 16:34

1 Answer 1

1

Carter is pointing you in the right direction, you might find the following info helpful.

http://en.wikipedia.org/wiki/List_of_PHP_accelerators

https://www.addedbytes.com/articles/for-beginners/output-caching-for-beginners/

http://www.phpfastcache.com/

http://www.wpulti.org/best-php-cache-scripts-classes/

http://codecanyon.net/item/php-simple-cache/4169137?ref=globalcube&ref=globalcube&clickthrough_id=384995784&redirect_back=true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.