Search the blog

The LazyCron module in Processwire runs a function at a given interval. It is “lazy” in the sense that, unlike a standard cron job, this requires a page load.

You will need to enable LazyCron module before proceeding.

To use LazyCron you just need to register a hook in your code (you can register it anywhere you would ordinarily register a hook).

function lazyCronTest(HookEvent $e) {
    
    // Do what you want here
    
}

\Processwire\wire()->addHook('LazyCron::every30Seconds', null, 'lazyCronTest');

If you want it to run like standard cron simply add a cron job that requests a page on your site at the desired interval and then the lazy cron will run regardless of website traffic.

For more information and options for the interval setting visit the LazyCron module page.

Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.