RockDaemon simplifies running long-running background tasks (daemons) with automatic lifecycle management. Ideal for tasks like PDF generation, email processing, or data synchronization that need to run continuously via cron jobs.
Why RockDaemon?
Running long-running tasks in PHP can be challenging:
Preventing multiple instances from running simultaneously
Manual restart capabilities
Automatic restart after deployments
Signal handling and graceful shutdown
Debug output control
Command-line argument parsing
Hosting environment compatibility
RockDaemon solves these problems with a simple, cron-based approach.
Example
<?php
// pdf-daemon.php
namespace ProcessWire;
use RockDaemon\Daemon;
require_once __DIR__ . '/public/index.php';
$rockdaemon = wire()->modules->get('RockDaemon');
$daemon = $rockdaemon->new('pdf-daemon');
$daemon
->run(function (Daemon $daemon) {
// get a newspaper page that has the "createPdf" checkbox enabled
$p = wire()->pages->get([
'template' => 'newspaper',
'createPdf' => 1,
]);
if (!$p->id) return $daemon->echo('Nothing to do');
$timer = Debug::startTimer();
$p->createPdf();
$ms = Debug::stopTimer($timer) * 1000;
$daemon->log(
message: "created PDF for $p in {$ms}ms",
logname: "pdf-create",
pruneDays: 30,
);
$daemon->run();
});
Docs + Download: baumrock.com/RockDaemon
Showcase in PW Weekly: https://weekly.pw/issue/590/