Jump to content

RockDaemon - Easy Background Task Management for ProcessWire ✅


bernhard
 Share

Recommended Posts

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/

  • Like 10
  • Thanks 1
Link to comment
Share on other sites

  • bernhard changed the title to RockDeamon - Easy Background Task Management for ProcessWire ✅
  • bernhard changed the title to RockDaemon - Easy Background Task Management for ProcessWire ✅

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...