Neuron-PHP

WebSocket extends DestinationBase
in package

Outputs log data to a WebSocket connection.

Maintains a persistent connection and automatically reconnects if disconnected.

This is a simple implementation using raw sockets with WebSocket protocol handshake.

Table of Contents

Properties

$_filters  : array<string|int, mixed>
$_format  : IFormat
$_parent  : ILogger|null
$_stdErr  : mixed
$_stdOut  : mixed
$host  : string
$isConnected  : bool
$maxReconnectAttempts  : int
$path  : string
$port  : int
$reconnectAttempts  : int
$reconnectDelay  : float
$socket  : mixed

Methods

__construct()  : mixed
__destruct()  : mixed
Close the WebSocket connection.
addFilter()  : bool
Adds a logging filter.
close()  : void
Closes the destination if required.
getParent()  : ILogger
Gets the parent logger.
getStdErr()  : mixed
getStdOut()  : mixed
log()  : void
Handles writing the log data after filtering and formatting.
open()  : bool
Configure the WebSocket connection.
removeFilter()  : bool
Removes a logging filter.
setFileHandles()  : void
Maps STDERR and STDOUT to file handles in non-CLI environments.
setFormat()  : void
Sets the formatter.
setParent()  : void
Sets the parent logger.
write()  : void
Write log data to the WebSocket connection.
connect()  : bool
Connect to the WebSocket server and perform handshake.
createFrame()  : string
Create a WebSocket frame for the message.
performHandshake()  : bool
Perform WebSocket handshake.
reconnect()  : bool
Attempt to reconnect to the WebSocket server.

Properties

$isConnected

private bool $isConnected = false

$maxReconnectAttempts

private int $maxReconnectAttempts = 5

$reconnectAttempts

private int $reconnectAttempts = 0

$reconnectDelay

private float $reconnectDelay = 1.0

Methods

__destruct()

Close the WebSocket connection.

public __destruct() : mixed

log()

Handles writing the log data after filtering and formatting.

public log(mixed $text, mixed $level[, mixed $context = [] ]) : void
Parameters
$text : mixed
  • Output that has been run through the formatter.
$level : mixed
  • Text output level.
$context : mixed = []
  • Optional context array

open()

Configure the WebSocket connection.

public open(array<string|int, mixed> $params) : bool

Parameters: url - WebSocket URL (ws://host:port/path)

Parameters
$params : array<string|int, mixed>
Return values
bool

removeFilter()

Removes a logging filter.

public removeFilter(IFilter $removeFilter) : bool
Parameters
$removeFilter : IFilter
Return values
bool

setFileHandles()

Maps STDERR and STDOUT to file handles in non-CLI environments.

public setFileHandles() : void

write()

Write log data to the WebSocket connection.

public write(string $text, Data $data) : void
Parameters
$text : string
$data : Data

connect()

Connect to the WebSocket server and perform handshake.

private connect() : bool
Return values
bool

createFrame()

Create a WebSocket frame for the message.

private createFrame(string $message) : string
Parameters
$message : string
Return values
string

performHandshake()

Perform WebSocket handshake.

private performHandshake() : bool
Return values
bool

reconnect()

Attempt to reconnect to the WebSocket server.

private reconnect() : bool
Return values
bool

        
On this page

Search results