\WorkermanWorker

Worker class A container for listening ports

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()
$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
VERSION
STATUS_STARTING
STATUS_RUNNING
STATUS_SHUTDOWN
STATUS_RELOADING
KILL_WORKER_TIMER_TIME
DEFAULT_BACKLOG
MAX_UDP_PACKAGE_SIZE
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()
$_autoloadRootPath
$_pauseAccept
$_masterPid
$_mainSocket
$_socketName
$_context
$_workers
$_pidMap
$_pidsToRestart
$_idMap
$_status
$_maxWorkerNameLength
$_maxSocketNameLength
$_maxUserNameLength
$_statisticsFile
$_startFile
$_OS
$_processForWindows
$_globalStatistics
$_availableEventLoops
$_builtinTransports
$_gracefulStop
$_outputStream
$_outputDecorated
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.

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

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

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

Construct.

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

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

outputStream()

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

Parameters

null $stream

Returns

boolean|resource