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

$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 layer protocol.

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

$statistics

$statistics : array

Statistics for status command.

Type

array

$onConnect

$onConnect : callback

Emitted when socket connection is successfully established.

Type

callback

$_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

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

$_remoteHost

$_remoteHost : string

Remote host.

Type

string

$_remotePort

$_remotePort : integer

Remote port.

Type

integer

$_connectStartTime

$_connectStartTime : string

Connect start time.

Type

string

$_remoteURI

$_remoteURI : string

Remote URI.

Type

string

$_contextOption

$_contextOption : array

Context option.

Type

array

$_reconnectTimer

$_reconnectTimer : integer

Reconnect timer.

Type

integer

$_builtinTransports

$_builtinTransports : array

PHP built-in protocols.

Type

array

Methods

__call()

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

Adding support of custom functions within protocols

Parameters

string $name
array $arguments

__construct()

__construct(string  $remote_address, array  $context_option = null) 

Construct.

Parameters

string $remote_address
array $context_option

Throws

\Exception

getStatus()

getStatus(boolean  $raw_output = true) : integer

Get status.

Parameters

boolean $raw_output

Returns

integer

send()

send(string  $send_buffer) : void|boolean

Sends data on the connection.

Parameters

string $send_buffer

Returns

void|boolean

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

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

close()

close(  $data = null) : void

Close connection.

Parameters

$data

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.

isIPv4()

isIPv4() : boolean

Is ipv4.

Returns

boolean

isIPv6()

isIPv6() : boolean

Is ipv6.

Returns

boolean

connect()

connect() : void

Do connect.

reconnect()

reconnect(integer  $after) : void

Reconnect.

Parameters

integer $after

cancelReconnect()

cancelReconnect() 

CancelReconnect.

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() : boolean

Whether send buffer is full.

Returns

boolean

emitError()

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

Try to emit onError callback.

Parameters

integer $code
string $msg