Service
Service
The Warlock application service class
class Service extends \Hazaar\Warlock\Agent\ContainerExtends: Hazaar\Warlock\Agent\Container
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 $nameType: string
config
protected array $configType: array
schedule
Runtime schedule queue keyed by generated action IDs.
protected array $scheduleType: array
next
public int $nextType: int
slept
Indicates whether the service entered a sleep cycle.
protected bool $sleptType: bool
lastCheckfile
Last timestamp when service file-change checks were performed.
private int $lastCheckfileType: int
serviceFile
Absolute path to the PHP file defining this service class.
private string $serviceFileType: string
serviceFileMtime
Last known modification time of the service source file.
private int $serviceFileMtimeType: int
lastHeartbeat
Timestamp when the most recent heartbeat was sent.
private int $lastHeartbeatType: int
Methods
__construct
public __construct(Protocol $protocol, ?string $name, array $config): voidParameters
| Parameter | Type | Description |
|---|---|---|
$protocol | Hazaar\Warlock\Protocol | |
$name | string | |
$config | array |
__processSchedule
Executes due scheduled actions and updates their next run times.
private __processSchedule(): voidReturns: void
This processes one-shot delays, recurring intervals, and cron actions, removing completed entries from the queue when appropriate.
__sendHeartbeat
protected __sendHeartbeat(): voidReturns: void
run
Default service loop entrypoint.
public run(): voidReturns: void
Override in concrete services to implement custom runtime behaviour.
delay
public delay(int $seconds, callable|string $callback, array $arguments): bool|stringReturns: bool|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$seconds | int | |
$callback | callable | string |
$arguments | array |
interval
public interval(int $seconds, callable|string $callback, array $params, ?string $tag, bool $overwrite): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$seconds | int | |
$callback | callable | string |
$params | array | |
$tag | string | |
$overwrite | bool |
schedule
public schedule(DateTime $date, callable|string $callback, array $params, ?string $tag, bool $overwrite): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$date | Hazaar\Util\DateTime | |
$callback | callable | string |
$params | array | |
$tag | string | |
$overwrite | bool |
cron
public cron(string $format, callable|string $callback, ?array $arguments): bool|stringReturns: bool|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$format | string | |
$callback | callable | string |
$arguments | array |
sleep
protected sleep(int $timeout, Status $checkStatus = 'Status::RUNNING', ?callable $iterationCallback): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int | |
$checkStatus | Hazaar\Warlock\Enum\Status | |
$iterationCallback | callable |
processCommand
protected processCommand(PacketType $command, ?\stdClass $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | Hazaar\Warlock\Enum\PacketType | |
$payload | stdClass |
initialize
Initializes the service by subscribing to events and scheduling actions
private initialize(array $config): boolReturns: bool
based on the provided configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000