Jump to content
maxf5

LazyCron: simple crawler/cache preloader

Recommended Posts

Hi guys,

this just came into my mind if you have MarkUpCache / TemplateCache enabled.

Is there a more elegant way than using a http request?

in site/ready.php:

<?php namespace ProcessWire;

function PreLoadCache(HookEvent $e) {
    $all = wire()->pages->find("has_parent!=2|1139|1029"); // no admin pages, contact forms, page tables
    $s=0; $f=0; $fn = '';
  
    $http = new WireHttp();

    foreach($all as $a) {
      
        $response = $http->get($a->httpUrl);
      
        if($response !== false) {
            $s++;
        } else {
            $fn .= $a->title . ", ";
            $f++;
        }
    }

    wire()->log()->save('croncaching', 'Cached: '. $s .' Pages, Failed at '. $f .' Pages: '. $fn .'');
}

wire()->addHook('LazyCron::every12Hours', null, 'PreLoadCache');

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...