Constants

READ_BUFFER_SIZE

READ_BUFFER_SIZE = 65535 : int

Read buffer size.

STATUS_INITIAL

STATUS_INITIAL = 0 : int

Status initial.

STATUS_CONNECTING

STATUS_CONNECTING = 1 : int

Status connecting.

STATUS_ESTABLISHED

STATUS_ESTABLISHED = 2 : int

Status connection established.

STATUS_CLOSING

STATUS_CLOSING = 4 : int

Status closing.

STATUS_CLOSED

STATUS_CLOSED = 8 : int

Status closed.

Properties

$onMessage

$onMessage : callable

Emitted when data is received.

Type

callable

$onClose

$onClose : callable

Emitted when the other end of the socket sends a FIN packet.

Type

callable

$onError

$onError : callable

Emitted when an error occurs with connection.

Type

callable

$onBufferFull

$onBufferFull : callable

Emitted when the send buffer becomes full.

Type

callable

$onBufferDrain

$onBufferDrain : callable

Emitted when the send buffer becomes empty.

Type

callable

$protocol

$protocol : \Workerman\Protocols\ProtocolInterface

Application layer protocol.

The format is like this Workerman\Protocols\Http.

Type

ProtocolInterface

$transport

$transport : string

Transport layer protocol.

Type

string

$worker

$worker : \Workerman\Worker

Which worker belong to.

Type

Worker

$bytesRead

$bytesRead : int

Bytes read.

Type

int

$bytesWritten

$bytesWritten : int

Bytes written.

Type

int

$id

$id : int

Connection->id.

Type

int

$maxSendBufferSize

$maxSendBufferSize : int

Sets the maximum send buffer size for the current connection.

OnBufferFull callback will be emited When the send buffer is full.

Type

int

$defaultMaxSendBufferSize

$defaultMaxSendBufferSize : int

Default send buffer size.

Type

int

$maxPackageSize

$maxPackageSize : int

Sets the maximum acceptable packet size for the current connection.

Type

int

$defaultMaxPackageSize

$defaultMaxPackageSize : int

Default maximum acceptable packet size.

Type

int

$connections

$connections : array

All connection instances.

Type

array

$_statusToString

$_statusToString : array

Status to string.

Type

array

$statistics

$statistics : array

Statistics for status command.

Type

array

$onConnect

$onConnect : callable|null

Emitted when socket connection is successfully established.

Type

callable|null

$_id

$_id : int

A copy of $worker->id which used to clean up the connection in worker->connections

Type

int

$_idRecorder

$_idRecorder : int

Id recorder.

Type

int

$_socket

$_socket : resource

Socket

Type

resource

$_sendBuffer

$_sendBuffer : string

Send buffer.

Type

string

$_recvBuffer

$_recvBuffer : string

Receive buffer.

Type

string

$_currentPackageLength

$_currentPackageLength : int

Current package length.

Type

int

$_status

$_status : int

Status.

Type

int

$_remoteAddress

$_remoteAddress : string

Remote address.

Type

string

$_isPaused

$_isPaused : bool

Is paused.

Type

bool

$_sslHandshakeCompleted

$_sslHandshakeCompleted : bool

SSL handshake completed or not.

Type

bool

$_remoteHost

$_remoteHost : string

Remote host.

Type

string

$_remotePort

$_remotePort : int

Remote port.

Type

int

$_connectStartTime

$_connectStartTime : float

Connect start time.

Type

float

$_remoteURI

$_remoteURI : string

Remote URI.

Type

string

$_contextOption

$_contextOption : array

Context option.

Type

array

$_reconnectTimer

$_reconnectTimer : int

Reconnect timer.

Type

int

$_builtinTransports

$_builtinTransports : array

PHP built-in protocols.

Type

array

Methods

__construct()

__construct(string  $remote_address, array  $context_option = array()) : mixed

Construct.

Parameters

string $remote_address
array $context_option

Throws

\Exception

Returns

mixed —

getStatus()

getStatus(bool  $raw_output = true) : int|string

Get status.

Parameters

bool $raw_output

Returns

int|string —

send()

send(mixed  $send_buffer) : void|bool

Sends data on the connection.

Parameters

mixed $send_buffer

Returns

void|bool —

getRemoteIp()

getRemoteIp() : string

Get remote IP.

Returns

string —

getRemotePort()

getRemotePort() : int

Get remote port.

Returns

int —

getRemoteAddress()

getRemoteAddress() : string

Get remote address.

Returns

string —

getLocalIp()

getLocalIp() : string

Get local IP.

Returns

string —

getLocalPort()

getLocalPort() : int

Get local port.

Returns

int —

getLocalAddress()

getLocalAddress() : string

Get local address.

Returns

string —

getSendBufferQueueSize()

getSendBufferQueueSize() : int

Get send buffer queue size.

Returns

int —

getRecvBufferQueueSize()

getRecvBufferQueueSize() : int

Get recv buffer queue size.

Returns

int —

isIpV4()

isIpV4() : mixed

Is ipv4.

return bool.

Returns

mixed —

isIpV6()

isIpV6() : mixed

Is ipv6.

return bool.

Returns

mixed —

pauseRecv()

pauseRecv() : void

Pauses the reading of data. That is onMessage will not be emitted. Useful to throttle back an upload.

resumeRecv()

resumeRecv() : void

Resumes reading after a call to pauseRecv.

baseRead()

baseRead(resource  $socket, bool  $check_eof = true) : void

Base read handler.

Parameters

resource $socket
bool $check_eof

baseWrite()

baseWrite() : void|bool

Base write handler.

Returns

void|bool —

doSslHandshake()

doSslHandshake(resource  $socket) : bool

SSL handshake.

Parameters

resource $socket

Returns

bool —

pipe()

pipe(self  $dest) : void

This method pulls all the data out of a readable stream, and writes it to the supplied destination.

Parameters

self $dest

consumeRecvBuffer()

consumeRecvBuffer(int  $length) : void

Remove $length of data from receive buffer.

Parameters

int $length

close()

close(string|null  $data = null) : void

Close connection.

Parameters

string|null $data

getSocket()

getSocket() : resource

Get the real socket.

Returns

resource —

bufferIsEmpty()

bufferIsEmpty() : bool

Whether send buffer is Empty.

Returns

bool —

destroy()

destroy() : void

Destroy connection.

__destruct()

__destruct() : void

Destruct.

isIPv4()

isIPv4() : bool

Is ipv4.

Returns

bool —

isIPv6()

isIPv6() : bool

Is ipv6.

Returns

bool —

connect()

connect() : void

Do connect.

reconnect()

reconnect(int  $after) : void

Reconnect.

Parameters

int $after

cancelReconnect()

cancelReconnect() : mixed

CancelReconnect.

Returns

mixed —

getRemoteHost()

getRemoteHost() : string

Get remote address.

Returns

string —

getRemoteURI()

getRemoteURI() : string

Get remote URI.

Returns

string —

checkConnection()

checkConnection() : void

Check connection is successfully established or faild.

checkBufferWillFull()

checkBufferWillFull() : void

Check whether the send buffer will be full.

bufferIsFull()

bufferIsFull() : bool

Whether send buffer is full.

Returns

bool —

emitError()

emitError(int  $code, string  $msg) : void

Try to emit onError callback.

Parameters

int $code
string $msg