Service
Service
The Warlock application service class
Services are long running processes that allow code to be executed on the server in the background without affecting or requiring any interaction with the front-end. Services are managed by the Warlock process and can be set to start when Warlock starts or enabled/disabled manually using the Hazaar\Warlock\Control class.
Services are executed within the Application context and therefore have access to everything (configs, classes/models, cache, etc) that your application front-end does.
See the "Services Documentation":https://hazaar.dev/docs/components/warlock/services for information on how to write and manage services.
Properties
name
Human-readable service name used in logs and control output.
protected string $nameconfig
protected array $configschedule
Runtime schedule queue keyed by generated action IDs.
protected array $schedulenext
public int $nextslept
Indicates whether the service entered a sleep cycle.
protected bool $sleptlastCheckfile
Last timestamp when service file-change checks were performed.
private int $lastCheckfileserviceFile
Absolute path to the PHP file defining this service class.
private string $serviceFileserviceFileMtime
Last known modification time of the service source file.
private int $serviceFileMtimeMethods
__construct
public __construct(Protocol $protocol, ?string $name, array $config): voidParameters
| Parameter | Type | Description |
|---|---|---|
$protocol | Protocol | |
$name | string | |
$config | array |
__processSchedule
Executes due scheduled actions and updates their next run times.
private __processSchedule(): voidThis processes one-shot delays, recurring intervals, and cron actions, removing completed entries from the queue when appropriate.
run
Default service loop entrypoint.
public run(): voidOverride in concrete services to implement custom runtime behaviour.
delay
public delay(int $seconds, string $callback, array $arguments): stringParameters
| Parameter | Type | Description |
|---|---|---|
$seconds | int | |
$callback | string | |
$arguments | array |
interval
public interval(int $seconds, string $callback, array $params, ?string $tag, bool $overwrite): stringParameters
| Parameter | Type | Description |
|---|---|---|
$seconds | int | |
$callback | string | |
$params | array | |
$tag | string | |
$overwrite | bool |
schedule
public schedule(DateTime $date, string $callback, array $params, ?string $tag, bool $overwrite): stringParameters
| Parameter | Type | Description |
|---|---|---|
$date | DateTime | |
$callback | string | |
$params | array | |
$tag | string | |
$overwrite | bool |
cron
public cron(string $format, string $callback, ?array $arguments): stringParameters
| Parameter | Type | Description |
|---|---|---|
$format | string | |
$callback | string | |
$arguments | array |
sleep
protected sleep(int $timeout, Status $checkStatus = 'Status::RUNNING'): boolParameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int | |
$checkStatus | Status |
initialize
Initializes the service by subscribing to events and scheduling actions
private initialize(array $config): boolbased on the provided configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
Generated by Hazaar API Doc Generator on Thu, 05 Mar 2026 04:14:39 +0000