WebSocket client implementation.
package |
Default |
---|
__construct(string $url, array $options = array())
string
Endpoint URL with schema
array
Websocket client options
$options = [
'timeout' => (int) Number of seconds until the connect() system call should timeout
'fragment_size' => (int) Split message to frames when exceeded fragment size limit
'logger' => (Psr\Log\LoggerInterface) Logger
]
close(integer $status = 1000, string $reason = null, integer $timeout = self::DEFAULT_TIMEOUT_SEC) : array
Sends "close" frame.
integer
Close status code
string
Any message that will be send in close frame
integer
Wait for response timeout
array
read code and socket frame payload
$return = [
'0' => (RtmClient\WebSocket\ReturnCode) Read result
'1' => (string) Close frame payload
]
connect() : void
Throws |
|
---|
generateSecKey(integer $length = 16) : string
integer
Length of generated hash
string
Hash
isConnected() : boolean
boolean
true if connected, false otherwise
isReusedPersistentConnection() : boolean
boolean
true if the connection is persistent and was reused. false otherwise
parseUrl(string $url) : array
string
URL with scheme
array
URL parts
$return = [
'scheme' => (string) e.g. http, wss
'socket_scheme' => (string) ssl or tcp
'host' => (string)
'path' => (string)
'query' => (string)
'port' => (string)
]
read(\RtmClient\WebSocket\Client::SYNC_READ|\RtmClient\WebSocket\Client::ASYNC_READ $mode = self::SYNC_READ, integer $timeout_sec, integer $timeout_microsec) : array
Throws |
|
---|
integer
The seconds part of the timeout to be set if read in Sync mode
integer
The microseconds part of the timeout to be set if read in Sync mode
array
read code and socket frame payload
$return = [
'0' => (RtmClient\WebSocket\ReturnCode) Read result
'1' => (string) Frame payload
]
readFrame(\RtmClient\WebSocket\Client::SYNC_READ|\RtmClient\WebSocket\Client::ASYNC_READ $mode, integer $timeout_sec, integer $timeout_microsec) : array
integer
The seconds part of the timeout to be set if read in Sync mode
integer
The microseconds part of the timeout to be set if read in Sync mode
array
Read result
$return = [
'0' => (RtmClient\WebSocket\ReturnCode) Read result
'1' => (string) Frame payload
]
send(string $payload, boolean $masked = true, \RtmClient\WebSocket\OpCode $opcode = \RtmClient\WebSocket\OpCode::TEXT) : true
Throws |
|
---|
string
Payload data
boolean
Use masking for message flag
true
if payload was sent
sendFragment(boolean $final, string $payload, \RtmClient\WebSocket\OpCode $opcode, boolean $masked) : integer
Throws |
|
---|
boolean
Mark fragment as Final
string
Payload data
boolean
Use mask for fragment
integer
bytes sent
socketRead(integer $length, \RtmClient\WebSocket\Client::SYNC_READ|\RtmClient\WebSocket\Client::ASYNC_READ $mode = self::SYNC_READ) : string
Throws |
|
---|
integer
Amount of bytes to be read from socket
string
Read data
socketWrite(string $data) : integer
Throws |
|
---|
string
Data to be send
integer
bytes sent
streamIsReadyToRead()
strToBin(string $str) : string
string
String to be converted to binary
string
Binary representation
DEFAULT_TIMEOUT_SEC
DEFAULT_FRAGMENT_SIZE
WEBSOCKET_MAGIC_KEY
SYNC_READ
ASYNC_READ
socket : resource
var |
---|
resource
is_connected : boolean
var |
---|
boolean
is_reused_p_connection : boolean
var |
---|
boolean
is_closing : boolean
var |
---|
boolean
frame_processing_in_progress : boolean
Uses to drop a connection in case if script died, but only a part of a frame was read or sent.
var |
---|
boolean