Constants

READ_BUFFER_SIZE

READ_BUFFER_SIZE = 65535 : integer

Read buffer size.

STATUS_INITIAL

STATUS_INITIAL = 0 : integer

Status initial.

STATUS_CONNECTING

STATUS_CONNECTING = 1 : integer

Status connecting.

STATUS_ESTABLISHED

STATUS_ESTABLISHED = 2 : integer

Status connection established.

STATUS_CLOSING

STATUS_CLOSING = 4 : integer

Status closing.

STATUS_CLOSED

STATUS_CLOSED = 8 : integer

Status closed.

Properties

$statistics

$statistics : array

Statistics for status command.

Type

array

$onMessage

$onMessage : callback

Emitted when data is received.

Type

callback

$onClose

$onClose : callback

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

Type

callback

$onError

$onError : callback

Emitted when an error occurs with connection.

Type

callback

$onBufferFull

$onBufferFull : callback

Emitted when the send buffer becomes full.

Type

callback

$onBufferDrain

$onBufferDrain : callback

Emitted when the send buffer becomes empty.

Type

callback

$transport

$transport : string

Transport (tcp/udp/unix/ssl).

Type

string

$bytesRead

$bytesRead : integer

Bytes read.

Type

integer

$bytesWritten

$bytesWritten : integer

Bytes written.

Type

integer

$id

$id : integer

Connection->id.

Type

integer

$maxSendBufferSize

$maxSendBufferSize : integer

Sets the maximum send buffer size for the current connection.

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

Type

integer

$defaultMaxSendBufferSize

$defaultMaxSendBufferSize : integer

Default send buffer size.

Type

integer

$maxPackageSize

$maxPackageSize : integer

Maximum acceptable packet size.

Type

integer

$connections

$connections : array

All connection instances.

Type

array

$_statusToString

$_statusToString : array

Status to string.

Type

array

$_id

$_id : integer

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

Type

integer

$_idRecorder

$_idRecorder : integer

Id recorder.

Type

integer

$_socket

$_socket : resource

Socket

Type

resource

$_sendBuffer

$_sendBuffer : string

Send buffer.

Type

string

$_recvBuffer

$_recvBuffer : string

Receive buffer.

Type

string

$_currentPackageLength

$_currentPackageLength : integer

Current package length.

Type

integer

$_status

$_status : integer

Connection status.

Type

integer

$_remoteAddress

$_remoteAddress : string

Remote address.

Type

string

$_isPaused

$_isPaused : boolean

Is paused.

Type

boolean

$_sslHandshakeCompleted

$_sslHandshakeCompleted : boolean

SSL handshake completed or not.

Type

boolean

Methods

send()

send(string  $send_buffer, boolean  $raw = false) : boolean|null

Sends data on the connection.

Parameters

string $send_buffer
boolean $raw

Returns

boolean|null

getRemoteIp()

getRemoteIp() : string

Get remote IP.

Returns

string

getRemotePort()

getRemotePort() : integer

Get remote port.

Returns

integer

getRemoteAddress()

getRemoteAddress() : string

Get remote address.

Returns

string

getLocalIp()

getLocalIp() : string

Get local IP.

Returns

string

getLocalPort()

getLocalPort() : integer

Get local port.

Returns

integer

getLocalAddress()

getLocalAddress() : string

Get local address.

Returns

string

isIPv4()

isIPv4() : boolean

Is ipv4.

Returns

boolean

isIPv6()

isIPv6() : boolean

Is ipv6.

Returns

boolean

close()

close(mixed  $data = null, boolean  $raw = false) : void

Close connection.

Parameters

mixed $data
boolean $raw

__call()

__call(string  $name, array  $arguments) : void

Adding support of custom functions within protocols

Parameters

string $name
array $arguments

__construct()

__construct(resource  $socket, string  $remote_address = '') 

Construct.

Parameters

resource $socket
string $remote_address

getStatus()

getStatus(boolean  $raw_output = true) : integer

Get status.

Parameters

boolean $raw_output

Returns

integer

getSendBufferQueueSize()

getSendBufferQueueSize() : integer

Get send buffer queue size.

Returns

integer

getRecvBufferQueueSize()

getRecvBufferQueueSize() : integer

Get recv buffer queue size.

Returns

integer

isIpV4()

isIpV4() 

Is ipv4.

return bool.

isIpV6()

isIpV6() 

Is ipv6.

return bool.

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, boolean  $check_eof = true) : void

Base read handler.

Parameters

resource $socket
boolean $check_eof

baseWrite()

baseWrite() : void|boolean

Base write handler.

Returns

void|boolean

doSslHandshake()

doSslHandshake(  $socket) : boolean

SSL handshake.

Parameters

$socket

Returns

boolean

pipe()

pipe(\Workerman\Connection\TcpConnection  $dest) : void

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

Parameters

\Workerman\Connection\TcpConnection $dest

consumeRecvBuffer()

consumeRecvBuffer(integer  $length) : void

Remove $length of data from receive buffer.

Parameters

integer $length

getSocket()

getSocket() : resource

Get the real socket.

Returns

resource

bufferIsEmpty()

bufferIsEmpty() : boolean

Whether send buffer is Empty.

Returns

boolean

destroy()

destroy() : void

Destroy connection.

__destruct()

__destruct() : void

Destruct.

checkBufferWillFull()

checkBufferWillFull() : void

Check whether the send buffer will be full.

bufferIsFull()

bufferIsFull() : boolean

Whether send buffer is full.

Returns

boolean