PHP Class Workerman\Worker

Afficher le fichier Open project: walkor/workerman Class Usage Examples

Méthodes publiques

Свойство 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

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

acceptConnection() public méthode

Accept a connection.
public acceptConnection ( resource $socket ) : void
$socket resource
Résultat void

acceptUdpConnection() public méthode

For udp package.
public acceptUdpConnection ( resource $socket ) : boolean
$socket resource
Résultat boolean

checkErrors() public static méthode

Check errors when current process exited.
public static checkErrors ( ) : void
Résultat void

checkSapiEnv() protected static méthode

Check sapi.
protected static checkSapiEnv ( ) : void
Résultat void

daemonize() protected static méthode

Run as deamon mode.
protected static daemonize ( )

displayUI() protected static méthode

Display staring UI.
protected static displayUI ( ) : void
Résultat void

exitAndClearAll() protected static méthode

Exit current process.
protected static exitAndClearAll ( ) : void
Résultat void

forkOneWorker() protected static méthode

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

forkWorkers() protected static méthode

Fork some worker processes.
protected static forkWorkers ( ) : void
Résultat void

getAllWorkerPids() protected static méthode

Get all pids of worker processes.
protected static getAllWorkerPids ( ) : array
Résultat array

getAllWorkers() public static méthode

Get all worker instances.
public static getAllWorkers ( ) : array
Résultat array

getCurrentUser() protected static méthode

Get unix user of current porcess.
protected static getCurrentUser ( ) : string
Résultat string

getErrorType() protected static méthode

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

getEventLoop() public static méthode

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

getEventLoopName() protected static méthode

Get event loop name.
protected static getEventLoopName ( ) : string
Résultat string

getId() protected static méthode

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

getSocketName() public méthode

Get socket name.
public getSocketName ( ) : string
Résultat string

init() protected static méthode

Init.
protected static init ( ) : void
Résultat void

initId() protected static méthode

return void
protected static initId ( )

initWorkers() protected static méthode

Init All worker instances.
protected static initWorkers ( ) : void
Résultat void

installSignal() protected static méthode

Install signal handler.
protected static installSignal ( ) : void
Résultat void

listen() public méthode

Listen port.
public listen ( )

log() public static méthode

Log.
public static log ( string $msg ) : void
$msg string
Résultat void

monitorWorkers() protected static méthode

Monitor all child processes.
protected static monitorWorkers ( ) : void
Résultat void

parseCommand() protected static méthode

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

reinstallSignal() protected static méthode

Reinstall signal handler.
protected static reinstallSignal ( ) : void
Résultat void

reload() protected static méthode

Execute reload.
protected static reload ( ) : void
Résultat void

resetStd() protected static méthode

Redirect standard input and output.
protected static resetStd ( )

run() public méthode

Run worker instance.
public run ( ) : void
Résultat void

runAll() public static méthode

Run all worker instances.
public static runAll ( ) : void
Résultat void

safeEcho() public static méthode

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

saveMasterPid() protected static méthode

Save pid.
protected static saveMasterPid ( )

setProcessTitle() protected static méthode

Set process name.
protected static setProcessTitle ( string $title ) : void
$title string
Résultat void

setUserAndGroup() public méthode

Set unix user and group for current process.
public setUserAndGroup ( ) : void
Résultat void

signalHandler() public static méthode

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

stop() public méthode

Stop current worker instance.
public stop ( ) : void
Résultat void

stopAll() public static méthode

Stop.
public static stopAll ( ) : void
Résultat void

writeStatisticsToStatusFile() protected static méthode

Write statistics data to disk.
protected static writeStatisticsToStatusFile ( ) : void
Résultat void

Property Details

$_autoloadRootPath protected_oe property

Root path for autoload.
protected string $_autoloadRootPath
Résultat string

$_availableEventLoops protected_oe static_oe property

Available event loops.
protected static array $_availableEventLoops
Résultat array

$_builtinTransports protected_oe static_oe property

PHP built-in protocols.
protected static array $_builtinTransports
Résultat array

$_context protected_oe property

Context of socket.
protected resource $_context
Résultat resource

$_eventLoopName protected_oe static_oe property

Current eventLoop name.
protected static string $_eventLoopName
Résultat string

$_globalStatistics protected_oe static_oe property

Status info of current worker process.
protected static array $_globalStatistics
Résultat array

$_idMap protected_oe static_oe property

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

$_mainSocket protected_oe property

Listening socket.
protected resource $_mainSocket
Résultat resource

$_masterPid protected_oe static_oe property

The PID of master process.
protected static int $_masterPid
Résultat integer

$_maxSocketNameLength protected_oe static_oe property

Maximum length of the socket names.
protected static int $_maxSocketNameLength
Résultat integer

$_maxUserNameLength protected_oe static_oe property

Maximum length of the process user names.
protected static int $_maxUserNameLength
Résultat integer

$_maxWorkerNameLength protected_oe static_oe property

Maximum length of the worker names.
protected static int $_maxWorkerNameLength
Résultat integer

$_pidMap protected_oe static_oe property

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

$_pidsToRestart protected_oe static_oe property

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

$_socketName protected_oe property

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

$_startFile protected_oe static_oe property

Start file.
protected static string $_startFile
Résultat string

$_statisticsFile protected_oe static_oe property

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

$_status protected_oe static_oe property

Current status.
protected static int $_status
Résultat integer

$_workers protected_oe static_oe property

All worker instances.
protected static array $_workers
Résultat array

$connections public_oe property

Store all connections of clients.
public array $connections
Résultat array

$count public_oe property

Number of worker processes.
public int $count
Résultat integer

$daemonize public_oe static_oe property

Daemonize.
public static bool $daemonize
Résultat boolean

$globalEvent public_oe static_oe property

Global event loop.
public static EventInterface,Workerman\Events $globalEvent
Résultat Workerman\Events\EventInterface

$group public_oe property

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

$id public_oe property

Worker id.
public int $id
Résultat integer

$logFile public_oe static_oe property

Log file.
public static mixed $logFile
Résultat mixed

$name public_oe property

Name of the worker processes.
public string $name
Résultat string

$onBufferDrain public_oe property

Emitted when the send buffer becomes empty.
public callback $onBufferDrain
Résultat callback

$onBufferFull public_oe property

Emitted when the send buffer becomes full.
public callback $onBufferFull
Résultat callback

$onClose public_oe property

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

$onConnect public_oe property

Emitted when a socket connection is successfully established.
public callback $onConnect
Résultat callback

$onError public_oe property

Emitted when an error occurs with connection.
public callback $onError
Résultat callback

$onMasterReload public_oe static_oe property

Emitted when the master process get reload signal.
public static callback $onMasterReload
Résultat callback

$onMessage public_oe property

Emitted when data is received.
public callback $onMessage
Résultat callback

$onWorkerReload public_oe property

Emitted when worker processes get reload signal.
public callback $onWorkerReload
Résultat callback

$onWorkerStart public_oe property

Emitted when worker processes start.
public callback $onWorkerStart
Résultat callback

$onWorkerStop public_oe property

Emitted when worker processes stoped.
public callback $onWorkerStop
Résultat callback

$pidFile public_oe static_oe property

The file to store master process PID.
public static string $pidFile
Résultat string

$protocol public_oe property

Application layer protocol.
public ProtocolInterface,Workerman\Protocols $protocol
Résultat Workerman\Protocols\ProtocolInterface

$reloadable public_oe property

reloadable.
public bool $reloadable
Résultat boolean

$reusePort public_oe property

reuse port.
public bool $reusePort
Résultat boolean

$stdoutFile public_oe static_oe property

Stdout file.
public static string $stdoutFile
Résultat string

$transport public_oe property

Transport layer protocol.
public string $transport
Résultat string

$user public_oe property

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