Main
Main
Properties
protocol
public Protocol $protocollog
public Logger $logconfig
The server configuration.
public Config $configinstances
private array $instancesenv
private string $env = 'development'pid
The process ID of this server.
private int $pidpidfile
private string $pidfile = '/var/run/warlock'silent
private bool $silenttime
Epoch of the last time stuff was processed.
private int $timewatcher
private Watcher $watcherrunning
private bool $running = trueshutdown
public int $shutdownsubscriptions
The wait queue. Clients subscribe to events and are added to this array.
private array $subscriptionsevents
The Event queue. Holds active events waiting to be seen.
private array $eventsmaster
The main socket for listening for incomming connections.
private mixed $masterstreams
Currently connected stream resources we are listening for data on.
private array $streamsclients
Currently connected clients.
private array $clientsagents
Currently connected agents.
private array $agentstv
Default select() timeout.
private int $tv = 1kvStore
private KVStore $kvStorecluster
private Cluster $clusterMethods
__construct
public __construct(?string $configFile, string $env = 'development'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$configFile | string | |
$env | string |
__signalHandler
private __signalHandler(int $signo, mixed $siginfo): voidParameters
| Parameter | Type | Description |
|---|---|---|
$signo | int | |
$siginfo | mixed |
bootstrap
Bootstrap the server.
public bootstrap(): selfThis method will set up the server, create the socket and prepare it for accepting connections. It will also set up the signal handlers for the server.
run
The main server run loop.
public run(): voidThis method will not return for as long as the server is running. While it is running it will process tasks, monitor services and distribute server signals.
shutdown
Initiate a server shutdown.
public shutdown(?int $delay): boolBecause this server manages running services, it's not really a good idea to just simply exist abruptly. This method will initiate a server shutdown which will nicely stop all services and once all services stop, the server will terminate safely.
Parameters
| Parameter | Type | Description |
|---|---|---|
$delay | int | how long in seconds before the shutdown should commence |
stop
public stop(bool $force, ?int $pid): boolParameters
| Parameter | Type | Description |
|---|---|---|
$force | bool | |
$pid | int |
setSilent
public setSilent(bool $silent = true): voidParameters
| Parameter | Type | Description |
|---|---|---|
$silent | bool |
disconnect
public disconnect(mixed $stream): boolParameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed |
clientAddStream
public clientAddStream(mixed $stream, ClientType $type = 'ClientType::BASIC'): falseParameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | |
$type | ClientType |
clientAdd
public clientAdd(Client $client): boolParameters
| Parameter | Type | Description |
|---|---|---|
$client | Client |
clientReplace
public clientReplace(mixed $stream, ?Client $client): boolParameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | |
$client | Client |
clientRemove
Removes a client from a stream.
public clientRemove(mixed $stream): voidBecause a client can have multiple stream connections (in legacy mode) this removes the client reference for that stream. Once there are no more references left the client is completely removed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed |
processCommand
Process administative commands for a client.
public processCommand(Client $client, PacketType $command, mixed $payload): voidParameters
| Parameter | Type | Description |
|---|---|---|
$client | Client | |
$command | PacketType | |
$payload | mixed |
trigger
public trigger(string $eventID, mixed $data, ?string $clientID, ?string $triggerID): boolParameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string | |
$data | mixed | |
$clientID | string | |
$triggerID | string |
subscribe
Subscribe a client to an event.
public subscribe(Client $client, string $eventID, ?array $filter): boolParameters
| Parameter | Type | Description |
|---|---|---|
$client | Client | The client to subscribe |
$eventID | string | The event ID to subscribe to |
$filter | array | Any event filters |
unsubscribe
Unsubscibe a client from an event.
public unsubscribe(Client $client, string $eventID): boolParameters
| Parameter | Type | Description |
|---|---|---|
$client | Client | The client to unsubscribe |
$eventID | string | The event ID to unsubscribe from |
getStatus
public getStatus(): voidgetLogger
public getLogger(string $name): LoggerParameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
fieldExists
private fieldExists(array $search, \stdClass $array): boolParameters
| Parameter | Type | Description |
|---|---|---|
$search | array | |
$array | \stdClass |
getFieldValue
private getFieldValue(array $search, \stdClass $array): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$search | array | |
$array | \stdClass |
eventFilter
Tests whether a event should be filtered.
private eventFilter(mixed $event, ?array $filter): boolReturns true if the event should be filtered (skipped), and false if the event should be processed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$event | mixed | the event to check |
$filter | array | the filter rule to test against |
eventProcess
Process the event queue for a specified client.
private eventProcess(Client $client, string $eventID, ?array $filter): boolThis method is executed when a client connects to see if there are any events waiting in the event queue that the client has not yet seen. If there are, the first event found is sent to the client, marked as seen and then processing stops.
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Client | |
$eventID | string | |
$filter | array |
subscriptionProcess
Process all subscriptions for a specified event.
private subscriptionProcess(string $eventID, ?string $triggerID): boolThis method is executed when a event is triggered. It is responsible for sending events to clients that are waiting for the event and marking them as seen by the client.
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string | |
$triggerID | string |
clientGet
Retrieve a client object for a stream resource.
private clientGet(mixed $stream): ?ClientParameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | The stream resource |
clientProcess
private clientProcess(mixed $stream): boolParameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed |
clientCheck
Checks the status of connected clients and pings them if they have not sent any data
private clientCheck(): voidwithin the configured number of seconds.
This function will only perform the check if the 'client.check' configuration value is greater than 0 and there is at least one client connected.
The default timeout for client inactivity is 60 seconds.
eventCleanup
private eventCleanup(): voidsocketSelect
private socketSelect(): voidwriteStartupMessage
private writeStartupMessage(string $message = 'Warlock starting up...'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$message | string |
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000