PHP Class Workerman\Worker

Mostrar archivo Open project: walkor/workerman Class Usage Examples

Public Properties

Property Type Description
$connections array Store all connections of clients.
$count integer Number of worker processes.
$daemonize boolean Daemonize.
$globalEvent Workerman\Events\EventInterface Global event loop.
$group string Unix group of processes, needs appropriate privileges (usually root).
$id integer Worker id.
$logFile mixed Log file.
$name string Name of the worker processes.
$onBufferDrain callback Emitted when the send buffer becomes empty.
$onBufferFull callback Emitted when the send buffer becomes full.
$onClose callback Emitted when the other end of the socket sends a FIN packet.
$onConnect callback Emitted when a socket connection is successfully established.
$onError callback Emitted when an error occurs with connection.
$onMasterReload callback Emitted when the master process get reload signal.
$onMessage callback Emitted when data is received.
$onWorkerReload callback Emitted when worker processes get reload signal.
$onWorkerStart callback Emitted when worker processes start.
$onWorkerStop callback Emitted when worker processes stoped.
$pidFile string The file to store master process PID.
$protocol Workerman\Protocols\ProtocolInterface Application layer protocol.
$reloadable boolean reloadable.
$reusePort boolean reuse port.
$stdoutFile string Stdout file.
$transport string Transport layer protocol.
$user string Unix user of processes, needs appropriate privileges (usually root).

Protected Properties

Property Type Description
$_autoloadRootPath string Root path for autoload.
$_availableEventLoops array Available event loops.
$_builtinTransports array PHP built-in protocols.
$_context resource Context of socket.
$_eventLoopName string Current eventLoop name.
$_globalStatistics array Status info of current worker process.
$_idMap array The format is like this [worker_id=>[0=>$pid, 1=>$pid, ..], ..].
$_mainSocket resource Listening socket.
$_masterPid integer The PID of master process.
$_maxSocketNameLength integer Maximum length of the socket names.
$_maxUserNameLength integer Maximum length of the process user names.
$_maxWorkerNameLength integer Maximum length of the worker names.
$_pidMap array The format is like this [worker_id=>[pid=>pid, pid=>pid, ..], ..]
$_pidsToRestart array The format is like this [pid=>pid, pid=>pid].
$_socketName string Socket name. The format is like this http://0.0.0.0:80 .
$_startFile string Start file.
$_statisticsFile string The file to store status info of current worker process.
$_status integer Current status.
$_workers array All worker instances.

Public Methods

Method Description
__construct ( string $socket_name = '', array $context_option = [] ) Construct.
acceptConnection ( resource $socket ) : void Accept a connection.
acceptUdpConnection ( resource $socket ) : boolean For udp package.
checkErrors ( ) : void Check errors when current process exited.
getAllWorkers ( ) : array Get all worker instances.
getEventLoop ( ) : Workerman\Events\EventInterface Get global event-loop instance.
getSocketName ( ) : string Get socket name.
listen ( ) Listen port.
log ( string $msg ) : void Log.
run ( ) : void Run worker instance.
runAll ( ) : void Run all worker instances.
safeEcho ( $msg ) Safe Echo.
setUserAndGroup ( ) : void Set unix user and group for current process.
signalHandler ( integer $signal ) Signal handler.
stop ( ) : void Stop current worker instance.
stopAll ( ) : void Stop.

Protected Methods

Method Description
checkSapiEnv ( ) : void Check sapi.
daemonize ( ) Run as deamon mode.
displayUI ( ) : void Display staring UI.
exitAndClearAll ( ) : void Exit current process.
forkOneWorker ( Worker $worker ) Fork one worker process.
forkWorkers ( ) : void Fork some worker processes.
getAllWorkerPids ( ) : array Get all pids of worker processes.
getCurrentUser ( ) : string Get unix user of current porcess.
getErrorType ( integer $type ) : string Get error message by error code.
getEventLoopName ( ) : string Get event loop name.
getId ( integer $worker_id, integer $pid ) Get worker id.
init ( ) : void Init.
initId ( ) Init idMap.
initWorkers ( ) : void Init All worker instances.
installSignal ( ) : void Install signal handler.
monitorWorkers ( ) : void Monitor all child processes.
parseCommand ( ) : void Parse command.
reinstallSignal ( ) : void Reinstall signal handler.
reload ( ) : void Execute reload.
resetStd ( ) Redirect standard input and output.
saveMasterPid ( ) Save pid.
setProcessTitle ( string $title ) : void Set process name.
writeStatisticsToStatusFile ( ) : void Write statistics data to disk.

Method Details

__construct() public method

Construct.
public __construct ( string $socket_name = '', array $context_option = [] )
$socket_name string
$context_option array

acceptConnection() public method

Accept a connection.
public acceptConnection ( resource $socket ) : void
$socket resource
return void

acceptUdpConnection() public method

For udp package.
public acceptUdpConnection ( resource $socket ) : boolean
$socket resource
return boolean

checkErrors() public static method

Check errors when current process exited.
public static checkErrors ( ) : void
return void

checkSapiEnv() protected static method

Check sapi.
protected static checkSapiEnv ( ) : void
return void

daemonize() protected static method

Run as deamon mode.
protected static daemonize ( )

displayUI() protected static method

Display staring UI.
protected static displayUI ( ) : void
return void

exitAndClearAll() protected static method

Exit current process.
protected static exitAndClearAll ( ) : void
return void

forkOneWorker() protected static method

Fork one worker process.
protected static forkOneWorker ( Worker $worker )
$worker Worker

forkWorkers() protected static method

Fork some worker processes.
protected static forkWorkers ( ) : void
return void

getAllWorkerPids() protected static method

Get all pids of worker processes.
protected static getAllWorkerPids ( ) : array
return array

getAllWorkers() public static method

Get all worker instances.
public static getAllWorkers ( ) : array
return array

getCurrentUser() protected static method

Get unix user of current porcess.
protected static getCurrentUser ( ) : string
return string

getErrorType() protected static method

Get error message by error code.
protected static getErrorType ( integer $type ) : string
$type integer
return string

getEventLoop() public static method

Get global event-loop instance.
public static getEventLoop ( ) : Workerman\Events\EventInterface
return Workerman\Events\EventInterface

getEventLoopName() protected static method

Get event loop name.
protected static getEventLoopName ( ) : string
return string

getId() protected static method

Get worker id.
protected static getId ( integer $worker_id, integer $pid )
$worker_id integer
$pid integer

getSocketName() public method

Get socket name.
public getSocketName ( ) : string
return string

init() protected static method

Init.
protected static init ( ) : void
return void

initId() protected static method

return void
protected static initId ( )

initWorkers() protected static method

Init All worker instances.
protected static initWorkers ( ) : void
return void

installSignal() protected static method

Install signal handler.
protected static installSignal ( ) : void
return void

listen() public method

Listen port.
public listen ( )

log() public static method

Log.
public static log ( string $msg ) : void
$msg string
return void

monitorWorkers() protected static method

Monitor all child processes.
protected static monitorWorkers ( ) : void
return void

parseCommand() protected static method

php yourfile.php start | stop | restart | reload | status
protected static parseCommand ( ) : void
return void

reinstallSignal() protected static method

Reinstall signal handler.
protected static reinstallSignal ( ) : void
return void

reload() protected static method

Execute reload.
protected static reload ( ) : void
return void

resetStd() protected static method

Redirect standard input and output.
protected static resetStd ( )

run() public method

Run worker instance.
public run ( ) : void
return void

runAll() public static method

Run all worker instances.
public static runAll ( ) : void
return void

safeEcho() public static method

Safe Echo.
public static safeEcho ( $msg )
$msg

saveMasterPid() protected static method

Save pid.
protected static saveMasterPid ( )

setProcessTitle() protected static method

Set process name.
protected static setProcessTitle ( string $title ) : void
$title string
return void

setUserAndGroup() public method

Set unix user and group for current process.
public setUserAndGroup ( ) : void
return void

signalHandler() public static method

Signal handler.
public static signalHandler ( integer $signal )
$signal integer

stop() public method

Stop current worker instance.
public stop ( ) : void
return void

stopAll() public static method

Stop.
public static stopAll ( ) : void
return void

writeStatisticsToStatusFile() protected static method

Write statistics data to disk.
protected static writeStatisticsToStatusFile ( ) : void
return void

Property Details

$_autoloadRootPath protected_oe property

Root path for autoload.
protected string $_autoloadRootPath
return string

$_availableEventLoops protected_oe static_oe property

Available event loops.
protected static array $_availableEventLoops
return array

$_builtinTransports protected_oe static_oe property

PHP built-in protocols.
protected static array $_builtinTransports
return array

$_context protected_oe property

Context of socket.
protected resource $_context
return resource

$_eventLoopName protected_oe static_oe property

Current eventLoop name.
protected static string $_eventLoopName
return string

$_globalStatistics protected_oe static_oe property

Status info of current worker process.
protected static array $_globalStatistics
return array

$_idMap protected_oe static_oe property

The format is like this [worker_id=>[0=>$pid, 1=>$pid, ..], ..].
protected static array $_idMap
return array

$_mainSocket protected_oe property

Listening socket.
protected resource $_mainSocket
return resource

$_masterPid protected_oe static_oe property

The PID of master process.
protected static int $_masterPid
return integer

$_maxSocketNameLength protected_oe static_oe property

Maximum length of the socket names.
protected static int $_maxSocketNameLength
return integer

$_maxUserNameLength protected_oe static_oe property

Maximum length of the process user names.
protected static int $_maxUserNameLength
return integer

$_maxWorkerNameLength protected_oe static_oe property

Maximum length of the worker names.
protected static int $_maxWorkerNameLength
return integer

$_pidMap protected_oe static_oe property

The format is like this [worker_id=>[pid=>pid, pid=>pid, ..], ..]
protected static array $_pidMap
return array

$_pidsToRestart protected_oe static_oe property

The format is like this [pid=>pid, pid=>pid].
protected static array $_pidsToRestart
return array

$_socketName protected_oe property

Socket name. The format is like this http://0.0.0.0:80 .
protected string $_socketName
return string

$_startFile protected_oe static_oe property

Start file.
protected static string $_startFile
return string

$_statisticsFile protected_oe static_oe property

The file to store status info of current worker process.
protected static string $_statisticsFile
return string

$_status protected_oe static_oe property

Current status.
protected static int $_status
return integer

$_workers protected_oe static_oe property

All worker instances.
protected static array $_workers
return array

$connections public_oe property

Store all connections of clients.
public array $connections
return array

$count public_oe property

Number of worker processes.
public int $count
return integer

$daemonize public_oe static_oe property

Daemonize.
public static bool $daemonize
return boolean

$globalEvent public_oe static_oe property

Global event loop.
public static EventInterface,Workerman\Events $globalEvent
return Workerman\Events\EventInterface

$group public_oe property

Unix group of processes, needs appropriate privileges (usually root).
public string $group
return string

$id public_oe property

Worker id.
public int $id
return integer

$logFile public_oe static_oe property

Log file.
public static mixed $logFile
return mixed

$name public_oe property

Name of the worker processes.
public string $name
return string

$onBufferDrain public_oe property

Emitted when the send buffer becomes empty.
public callback $onBufferDrain
return callback

$onBufferFull public_oe property

Emitted when the send buffer becomes full.
public callback $onBufferFull
return callback

$onClose public_oe property

Emitted when the other end of the socket sends a FIN packet.
public callback $onClose
return callback

$onConnect public_oe property

Emitted when a socket connection is successfully established.
public callback $onConnect
return callback

$onError public_oe property

Emitted when an error occurs with connection.
public callback $onError
return callback

$onMasterReload public_oe static_oe property

Emitted when the master process get reload signal.
public static callback $onMasterReload
return callback

$onMessage public_oe property

Emitted when data is received.
public callback $onMessage
return callback

$onWorkerReload public_oe property

Emitted when worker processes get reload signal.
public callback $onWorkerReload
return callback

$onWorkerStart public_oe property

Emitted when worker processes start.
public callback $onWorkerStart
return callback

$onWorkerStop public_oe property

Emitted when worker processes stoped.
public callback $onWorkerStop
return callback

$pidFile public_oe static_oe property

The file to store master process PID.
public static string $pidFile
return string

$protocol public_oe property

Application layer protocol.
public ProtocolInterface,Workerman\Protocols $protocol
return Workerman\Protocols\ProtocolInterface

$reloadable public_oe property

reloadable.
public bool $reloadable
return boolean

$reusePort public_oe property

reuse port.
public bool $reusePort
return boolean

$stdoutFile public_oe static_oe property

Stdout file.
public static string $stdoutFile
return string

$transport public_oe property

Transport layer protocol.
public string $transport
return string

$user public_oe property

Unix user of processes, needs appropriate privileges (usually root).
public string $user
return string