Main
Main
Primary Warlock server runtime and connection orchestrator.
class MainProperties
protocol
Packet protocol used by connected clients and agents.
public Protocol $protocolType: Hazaar\Warlock\Protocol
log
Root logger for server output.
public Logger $logType: Hazaar\Warlock\Logger
config
The server configuration.
public Config $configType: Hazaar\Config
instances
private array $instancesType: array
env
Active runtime environment name.
private string $env = 'development'Type: string
runtime
Runtime implementation for process execution and lifecycle management.
private Runtime $runtimeType: Hazaar\Application\Runtime
pid
The process ID of this server.
private int $pidType: int
pidfile
PID file path used for external stop/restart controls.
private string $pidfile = '/var/run/warlock'Type: string
silent
Enables/disables startup log output.
private bool $silentType: bool
time
Epoch of the last time stuff was processed.
private int $timeType: int
watcher
Optional process watcher helper.
private Watcher $watcherType: Hazaar\Warlock\Server\Watcher
running
private bool $running = trueType: bool
shutdown
public int $shutdownType: int
subscriptions
The wait queue. Clients subscribe to events and are added to this array.
private array $subscriptionsType: array
events
The Event queue. Holds active events waiting to be seen.
private array $eventsType: array
master
The main socket for listening for incomming connections.
private mixed $masterType: mixed
streams
Currently connected stream resources we are listening for data on.
private array $streamsType: array
clients
Currently connected clients.
private array $clientsType: array
agents
Currently connected agents.
private array $agentsType: array
tv
Default select() timeout.
private int $tv = 1Type: int
kvStore
Key/value storage component.
private KVStore $kvStoreType: Hazaar\Warlock\Server\Component\KVStore
cluster
Cluster peer-management component.
private Cluster $clusterType: Hazaar\Warlock\Server\Component\Cluster
authenticator
private Authenticator $authenticatorType: Hazaar\Warlock\Server\Authenticator
Methods
__construct
public __construct(?string $configFile, string $env = 'development'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$configFile | string | server config filename |
$env | string | runtime environment |
__signalHandler
Static signal handler for server lifecycle signals.
private __signalHandler(int $signo, mixed $siginfo): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$signo | int | |
$siginfo | mixed |
bootstrap
Bootstrap the server.
public bootstrap(): selfReturns: self
This 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): boolReturns: bool
Because 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$force | bool | |
$pid | int |
setSilent
public setSilent(bool $silent = true): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$silent | bool |
disconnect
public disconnect(mixed $stream): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed |
clientAddStream
public clientAddStream(mixed $stream, ClientType $type = 'ClientType::USER'): Client|falseReturns: Hazaar\Warlock\Server\Client|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | |
$type | Hazaar\Warlock\Enum\ClientType |
clientAdd
public clientAdd(Client $client): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Hazaar\Warlock\Server\Client |
clientReplace
public clientReplace(mixed $stream, ?Client $client): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | |
$client | Hazaar\Warlock\Server\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): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Hazaar\Warlock\Server\Client | |
$command | Hazaar\Warlock\Enum\PacketType | |
$payload | mixed |
trigger
public trigger(string $eventID, mixed $data, ?string $clientID, ?string $triggerID): boolReturns: bool
Parameters
| 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Hazaar\Warlock\Server\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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Hazaar\Warlock\Server\Client | The client to unsubscribe |
$eventID | string | The event ID to unsubscribe from |
getStatus
public getStatus(): \stdClassReturns: stdClass
getLogger
public getLogger(string $name): LoggerReturns: Hazaar\Warlock\Logger
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
authenticate
Router for authentication requests.
public authenticate(string $username, string $password, ?Client $client): boolReturns: bool
This will route the request to the appropriate authentication handler based on the server configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$username | string | the username provided by the client |
$password | string | the password provided by the client |
$client | Hazaar\Warlock\Server\Client | the client object for the client being authenticated, if available. This is provided for authentication methods that require client context, such as IP address or connection time. It may be null if no client context is available (e.g. during initial connection before a client object is created). |
fieldExists
private fieldExists(array $search, \stdClass $array): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$search | array | |
$array | stdClass |
getFieldValue
private getFieldValue(array $search, \stdClass $array): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$search | array | |
$array | stdClass |
eventFilter
Tests whether a event should be filtered.
private eventFilter(array $event, ?array $filter): boolReturns: bool
Returns true if the event should be filtered (skipped), and false if the event should be processed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$event | array | 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): boolReturns: bool
This 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 | Hazaar\Warlock\Server\Client | |
$eventID | string | |
$filter | array |
subscriptionProcess
Process all subscriptions for a specified event.
private subscriptionProcess(string $eventID, ?string $triggerID): boolReturns: bool
This 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): ?ClientReturns: Hazaar\Warlock\Server\Client
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed | The stream resource |
clientProcess
private clientProcess(mixed $stream): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | mixed |
clientCheck
Checks the status of connected clients and pings them if they have not sent any data
private clientCheck(): voidReturns: void
within 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(): voidReturns: void
socketSelect
private socketSelect(): voidReturns: void
writeStartupMessage
private writeStartupMessage(string $message = 'Warlock starting up...'): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000