\GatewayWorkerBusinessWorker

BusinessWorker 用于处理Gateway转发来的数据

Summary

Methods
Properties
Constants
runAll()
getAllWorkers()
getEventLoop()
signalHandler()
resetStd()
getStartFilesForWindows()
forkOneWorkerForWindows()
checkWorkerStatusForWindows()
setUserAndGroup()
stopAll()
checkIfChildRunning()
getStatus()
getGracefulStop()
checkErrors()
log()
safeEcho()
__construct()
listen()
unlisten()
pauseAccept()
resumeAccept()
getSocketName()
run()
stop()
acceptConnection()
acceptUdpConnection()
connectToRegister()
onRegisterConnectionMessage()
onGatewayMessage()
onGatewayClose()
tryToConnectGateway()
checkGatewayConnections()
onConnectGateway()
onGatewayError()
getAllGatewayAddresses()
timeoutHandler()
$id
$name
$count
$user
$group
$reloadable
$reusePort
$onWorkerStart
$onConnect
$onMessage
$onClose
$onError
$onBufferFull
$onBufferDrain
$onWorkerStop
$onWorkerReload
$transport
$connections
$protocol
$stopping
$daemonize
$stdoutFile
$pidFile
$logFile
$globalEvent
$onMasterReload
$onMasterStop
$eventLoopClass
$gatewayConnections
$registerAddress
$eventHandler
$processTimeout
$processTimeoutHandler
$secretKey
$sendToGatewayBufferSize
VERSION
STATUS_STARTING
STATUS_RUNNING
STATUS_SHUTDOWN
STATUS_RELOADING
KILL_WORKER_TIMER_TIME
DEFAULT_BACKLOG
MAX_UDP_PACKAGE_SIZE
PERSISTENCE_CONNECTION_PING_INTERVAL
checkSapiEnv()
init()
initWorkers()
initId()
getCurrentUser()
displayUI()
parseCommand()
formatStatusData()
installSignal()
reinstallSignal()
daemonize()
saveMasterPid()
getEventLoopName()
getAllWorkerPids()
forkWorkers()
forkWorkersForLinux()
forkWorkersForWindows()
forkOneWorkerForLinux()
getId()
setProcessTitle()
monitorWorkers()
monitorWorkersForLinux()
monitorWorkersForWindows()
exitAndClearAll()
reload()
writeStatisticsToStatusFile()
writeConnectionsStatisticsToStatusFile()
getErrorType()
onWorkerStart()
onWorkerReload()
onWorkerStop()
$_autoloadRootPath
$_pauseAccept
$_masterPid
$_mainSocket
$_socketName
$_context
$_workers
$_pidMap
$_pidsToRestart
$_idMap
$_status
$_maxWorkerNameLength
$_maxSocketNameLength
$_maxUserNameLength
$_statisticsFile
$_startFile
$_OS
$_processForWindows
$_globalStatistics
$_availableEventLoops
$_builtinTransports
$_gracefulStop
$_outputStream
$_outputDecorated
$_onWorkerStart
$_onWorkerReload
$_onWorkerStop
$_registerConnection
$_connectingGatewayAddresses
$_gatewayAddresses
$_waitingConnectGatewayAddresses
$_eventOnConnect
$_eventOnMessage
$_eventOnClose
$_eventOnWebSocketConnect
$_sessionVersion
N/A
outputStream()
No private properties found
N/A

Constants

VERSION

VERSION = '3.5.14' : string

Version.

STATUS_STARTING

STATUS_STARTING = 1 : integer

Status starting.

STATUS_RUNNING

STATUS_RUNNING = 2 : integer

Status running.

STATUS_SHUTDOWN

STATUS_SHUTDOWN = 4 : integer

Status shutdown.

STATUS_RELOADING

STATUS_RELOADING = 8 : integer

Status reloading.

KILL_WORKER_TIMER_TIME

KILL_WORKER_TIMER_TIME = 2 : integer

After sending the restart command to the child process KILL_WORKER_TIMER_TIME seconds, if the process is still living then forced to kill.

DEFAULT_BACKLOG

DEFAULT_BACKLOG = 102400 : integer

Default backlog. Backlog is the maximum length of the queue of pending connections.

MAX_UDP_PACKAGE_SIZE

MAX_UDP_PACKAGE_SIZE = 65535 : integer

Max udp package size.

PERSISTENCE_CONNECTION_PING_INTERVAL

PERSISTENCE_CONNECTION_PING_INTERVAL = 25 : integer

用于保持长连接的心跳时间间隔

Properties

$id

$id : integer

Worker id.

Type

integer

$name

$name : string

Name of the worker processes.

Type

string

$count

$count : integer

Number of worker processes.

Type

integer

$user

$user : string

Unix user of processes, needs appropriate privileges (usually root).

Type

string

$group

$group : string

Unix group of processes, needs appropriate privileges (usually root).

Type

string

$reloadable

$reloadable : boolean

reloadable.

Type

boolean

$reusePort

$reusePort : boolean

reuse port.

Type

boolean

$onWorkerStart

$onWorkerStart : callback

Emitted when worker processes start.

Type

callback

$onConnect

$onConnect : callback

Emitted when a socket connection is successfully established.

Type

callback

$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

$onWorkerStop

$onWorkerStop : callback

Emitted when worker processes stoped.

Type

callback

$onWorkerReload

$onWorkerReload : callback

Emitted when worker processes get reload signal.

Type

callback

$transport

$transport : string

Transport layer protocol.

Type

string

$connections

$connections : array

Store all connections of clients.

Type

array

$protocol

$protocol : string

Application layer protocol.

Type

string

$stopping

$stopping : boolean

Is worker stopping ?

Type

boolean

$daemonize

$daemonize : boolean

Daemonize.

Type

boolean

$stdoutFile

$stdoutFile : string

Stdout file.

Type

string

$pidFile

$pidFile : string

The file to store master process PID.

Type

string

$logFile

$logFile : mixed

Log file.

Type

mixed

$onMasterReload

$onMasterReload : callback

Emitted when the master process get reload signal.

Type

callback

$onMasterStop

$onMasterStop : callback

Emitted when the master process terminated.

Type

callback

$eventLoopClass

$eventLoopClass : string

EventLoopClass

Type

string

$gatewayConnections

$gatewayConnections : array

保存与 gateway 的连接 connection 对象

Type

array

$registerAddress

$registerAddress : string|array

注册中心地址

Type

string|array

$eventHandler

$eventHandler : string

事件处理类,默认是 Event 类

Type

string

$processTimeout

$processTimeout : integer

业务超时时间,可用来定位程序卡在哪里

Type

integer

$processTimeoutHandler

$processTimeoutHandler : callable

业务超时时间,可用来定位程序卡在哪里

Type

callable

$secretKey

$secretKey : string

秘钥

Type

string

$sendToGatewayBufferSize

$sendToGatewayBufferSize : integer

businessWorker进程将消息转发给gateway进程的发送缓冲区大小

Type

integer

$_autoloadRootPath

$_autoloadRootPath : string

Root path for autoload.

Type

string

$_pauseAccept

$_pauseAccept : boolean

Pause accept new connections or not.

Type

boolean

$_masterPid

$_masterPid : integer

The PID of master process.

Type

integer

$_mainSocket

$_mainSocket : resource

Listening socket.

Type

resource

$_socketName

$_socketName : string

Socket name. The format is like this http://0.0.0.0:80 .

Type

string

$_context

$_context : resource

Context of socket.

Type

resource

$_workers

$_workers : array<mixed,\Workerman\Worker>

All worker instances.

Type

array<mixed,\Workerman\Worker>

$_pidMap

$_pidMap : array

All worker porcesses pid.

The format is like this [worker_id=>[pid=>pid, pid=>pid, ..], ..]

Type

array

$_pidsToRestart

$_pidsToRestart : array

All worker processes waiting for restart.

The format is like this [pid=>pid, pid=>pid].

Type

array

$_idMap

$_idMap : array

Mapping from PID to worker process ID.

The format is like this [worker_id=>[0=>$pid, 1=>$pid, ..], ..].

Type

array

$_status

$_status : integer

Current status.

Type

integer

$_maxWorkerNameLength

$_maxWorkerNameLength : integer

Maximum length of the worker names.

Type

integer

$_maxSocketNameLength

$_maxSocketNameLength : integer

Maximum length of the socket names.

Type

integer

$_maxUserNameLength

$_maxUserNameLength : integer

Maximum length of the process user names.

Type

integer

$_statisticsFile

$_statisticsFile : string

The file to store status info of current worker process.

Type

string

$_startFile

$_startFile : string

Start file.

Type

string

$_OS

$_OS : string

OS.

Type

string

$_processForWindows

$_processForWindows : array

Processes for windows.

Type

array

$_globalStatistics

$_globalStatistics : array

Status info of current worker process.

Type

array

$_availableEventLoops

$_availableEventLoops : array

Available event loops.

Type

array

$_builtinTransports

$_builtinTransports : array

PHP built-in protocols.

Type

array

$_gracefulStop

$_gracefulStop : string

Graceful stop or not.

Type

string

$_outputStream

$_outputStream : resource

Standard output stream

Type

resource

$_outputDecorated

$_outputDecorated : boolean

If $outputStream support decorated

Type

boolean

$_onWorkerStart

$_onWorkerStart : callback

保存用户设置的 worker 启动回调

Type

callback

$_onWorkerReload

$_onWorkerReload : callback

保存用户设置的 workerReload 回调

Type

callback

$_onWorkerStop

$_onWorkerStop : callback

保存用户设置的 workerStop 回调

Type

callback

$_connectingGatewayAddresses

$_connectingGatewayAddresses : array

处于连接状态的 gateway 通讯地址

Type

array

$_gatewayAddresses

$_gatewayAddresses : array

所有 geteway 内部通讯地址

Type

array

$_waitingConnectGatewayAddresses

$_waitingConnectGatewayAddresses : array

等待连接个 gateway 地址

Type

array

$_eventOnConnect

$_eventOnConnect : callback

Event::onConnect 回调

Type

callback

$_eventOnMessage

$_eventOnMessage : callback

Event::onMessage 回调

Type

callback

$_eventOnClose

$_eventOnClose : callback

Event::onClose 回调

Type

callback

$_eventOnWebSocketConnect

$_eventOnWebSocketConnect : null

websocket回调

Type

null

$_sessionVersion

$_sessionVersion : array

SESSION 版本缓存

Type

array

Methods

runAll()

runAll() : void

Run all worker instances.

getAllWorkers()

getAllWorkers() : array

Get all worker instances.

Returns

array

signalHandler()

signalHandler(integer  $signal) 

Signal handler.

Parameters

integer $signal

resetStd()

resetStd() 

Redirect standard input and output.

Throws

\Exception

getStartFilesForWindows()

getStartFilesForWindows() : array

Get start files for windows.

Returns

array

forkOneWorkerForWindows()

forkOneWorkerForWindows(string  $start_file) 

Fork one worker process.

Parameters

string $start_file

checkWorkerStatusForWindows()

checkWorkerStatusForWindows() : void

check worker status for windows.

setUserAndGroup()

setUserAndGroup() : void

Set unix user and group for current process.

stopAll()

stopAll() : void

Stop.

checkIfChildRunning()

checkIfChildRunning() 

check if child processes is really running

getStatus()

getStatus() : \Workerman\number

Get process status.

Returns

\Workerman\number

getGracefulStop()

getGracefulStop() : boolean

If stop gracefully.

Returns

boolean

checkErrors()

checkErrors() : void

Check errors when current process exited.

log()

log(string  $msg) : void

Log.

Parameters

string $msg

safeEcho()

safeEcho(  $msg, boolean  $decorated = false) : boolean

Safe Echo.

Parameters

$msg
boolean $decorated

Returns

boolean

__construct()

__construct(string  $socket_name = '', array  $context_option = array()) 

构造函数

Parameters

string $socket_name
array $context_option

listen()

listen() 

Listen.

Throws

\Exception

unlisten()

unlisten() : void

Unlisten.

pauseAccept()

pauseAccept() : void

Pause accept new connections.

resumeAccept()

resumeAccept() : void

Resume accept new connections.

getSocketName()

getSocketName() : string

Get socket name.

Returns

string

run()

run() : void

Run worker instance.

stop()

stop() : void

Stop current worker instance.

acceptConnection()

acceptConnection(resource  $socket) : void

Accept a connection.

Parameters

resource $socket

acceptUdpConnection()

acceptUdpConnection(resource  $socket) : boolean

For udp package.

Parameters

resource $socket

Returns

boolean

connectToRegister()

connectToRegister() : void

连接服务注册中心

onRegisterConnectionMessage()

onRegisterConnectionMessage(  $register_connection,   $data) : void

当注册中心发来消息时

Parameters

$register_connection
$data

onGatewayMessage()

onGatewayMessage(\Workerman\Connection\TcpConnection  $connection, mixed  $data) 

当 gateway 转发来数据时

Parameters

\Workerman\Connection\TcpConnection $connection
mixed $data

onGatewayClose()

onGatewayClose(\Workerman\Connection\TcpConnection  $connection) : void

当与 Gateway 的连接断开时触发

Parameters

\Workerman\Connection\TcpConnection $connection

tryToConnectGateway()

tryToConnectGateway(string  $addr) 

尝试连接 Gateway 内部通讯地址

Parameters

string $addr

checkGatewayConnections()

checkGatewayConnections(array  $addresses_list) 

检查 gateway 的通信端口是否都已经连 如果有未连接的端口,则尝试连接

Parameters

array $addresses_list

onConnectGateway()

onConnectGateway(\Workerman\Connection\TcpConnection  $connection) : void

当连接上 gateway 的通讯端口时触发 将连接 connection 对象保存起来

Parameters

\Workerman\Connection\TcpConnection $connection

onGatewayError()

onGatewayError(\Workerman\Connection\TcpConnection  $connection, integer  $error_no, string  $error_msg) 

当与 gateway 的连接出现错误时触发

Parameters

\Workerman\Connection\TcpConnection $connection
integer $error_no
string $error_msg

getAllGatewayAddresses()

getAllGatewayAddresses() : array

获取所有 Gateway 内部通讯地址

Returns

array

timeoutHandler()

timeoutHandler(integer  $signal) 

业务超时回调

Parameters

integer $signal

Throws

\Exception

checkSapiEnv()

checkSapiEnv() : void

Check sapi.

init()

init() : void

Init.

initWorkers()

initWorkers() : void

Init All worker instances.

initId()

initId() 

Init idMap.

return void

getCurrentUser()

getCurrentUser() : string

Get unix user of current porcess.

Returns

string

displayUI()

displayUI() : void

Display staring UI.

parseCommand()

parseCommand() : void

Parse command.

formatStatusData()

formatStatusData() : string

Format status data.

Returns

string

installSignal()

installSignal() : void

Install signal handler.

reinstallSignal()

reinstallSignal() : void

Reinstall signal handler.

daemonize()

daemonize() 

Run as deamon mode.

Throws

\Exception

saveMasterPid()

saveMasterPid() 

Save pid.

Throws

\Exception

getEventLoopName()

getEventLoopName() : string

Get event loop name.

Returns

string

getAllWorkerPids()

getAllWorkerPids() : array

Get all pids of worker processes.

Returns

array

forkWorkers()

forkWorkers() : void

Fork some worker processes.

forkWorkersForLinux()

forkWorkersForLinux() : void

Fork some worker processes.

forkWorkersForWindows()

forkWorkersForWindows() : void

Fork some worker processes.

forkOneWorkerForLinux()

forkOneWorkerForLinux(\Workerman\Worker  $worker) 

Fork one worker process.

Parameters

\Workerman\Worker $worker

Throws

\Exception

getId()

getId(integer  $worker_id, integer  $pid) : integer

Get worker id.

Parameters

integer $worker_id
integer $pid

Returns

integer

setProcessTitle()

setProcessTitle(string  $title) : void

Set process name.

Parameters

string $title

monitorWorkers()

monitorWorkers() : void

Monitor all child processes.

monitorWorkersForLinux()

monitorWorkersForLinux() : void

Monitor all child processes.

monitorWorkersForWindows()

monitorWorkersForWindows() : void

Monitor all child processes.

exitAndClearAll()

exitAndClearAll() : void

Exit current process.

reload()

reload() : void

Execute reload.

writeStatisticsToStatusFile()

writeStatisticsToStatusFile() : void

Write statistics data to disk.

writeConnectionsStatisticsToStatusFile()

writeConnectionsStatisticsToStatusFile() : void

Write statistics data to disk.

getErrorType()

getErrorType(integer  $type) : string

Get error message by error code.

Parameters

integer $type

Returns

string

onWorkerStart()

onWorkerStart() : void

当进程启动时一些初始化工作

onWorkerReload()

onWorkerReload(\Workerman\Worker  $worker) 

onWorkerReload 回调

Parameters

\Workerman\Worker $worker

onWorkerStop()

onWorkerStop() : void

当进程关闭时一些清理工作

outputStream()

outputStream(null  $stream = null) : boolean|resource

Parameters

null $stream

Returns

boolean|resource