PHP Class vyants\daemon\DaemonController

Author: Vladimir Yants ([email protected])
Inheritance: extends yii\console\Controller
Afficher le fichier Open project: vyants/yii2-daemon Class Usage Examples

Méthodes publiques

Свойство Type Description
$demonize boolean Run controller as Daemon
$isMultiInstance boolean allow daemon create a few instances
$maxChildProcesses int max daemon instances

Protected Properties

Свойство Type Description
$currentJobs [] array of running instances
$logDir
$memoryLimit Memory limit for daemon, must bee less than php memory_limit
$parentPID int main procces pid
$pidDir
$sleep Delay between task list checking

Méthodes publiques

Méthode Description
__destruct ( )
actionIndex ( ) : boolean Base action, you can\t override or create another actions
beforeAction ( Action $action ) : boolean Prevent non index action running
getPidPath ( string $daemon = null ) : string
getProcessName ( $route = null ) : string
init ( ) Init function
options ( string $actionID ) : array Возвращает доступные опции
runDaemon ( string $job ) : boolean Tasks runner
signalHandler ( $signo, null $pid = null, null $status = null ) PCNTL signals handler
stderr ( string $string ) : integer If in daemon mode - no write to console
stdout ( string $string ) : boolean | integer If in daemon mode - no write to console

Méthodes protégées

Méthode Description
changeProcessName ( ) Set new process name
cleanLog ( ) Empty log queue
closeStdStreams ( ) Close std streams and open to /dev/null need some class properties
defineJobExtractor ( &$jobs ) : mixed Fetch one task from array of tasks
defineJobs ( ) : array Extract current unprocessed jobs You can extract jobs from DB (DataProvider will be great), queue managers (ZMQ, RabbiMQ etc), redis and so on
deletePid ( ) Delete pid file
doJob ( $job ) : boolean Daemon worker body
flushLog ( $final = false ) Empty log queue
halt ( $code, $message = null ) Stop process and show or write message
initLogger ( ) Adjusting logger. You can override it.
renewConnections ( ) Renew connections

Private Methods

Méthode Description
loop ( ) : boolean Main Loop
writeConsole ( $message ) Show message in console

Method Details

__destruct() public méthode

public __destruct ( )

actionIndex() final public méthode

Base action, you can\t override or create another actions
final public actionIndex ( ) : boolean
Résultat boolean

beforeAction() public méthode

Prevent non index action running
public beforeAction ( Action $action ) : boolean
$action yii\base\Action
Résultat boolean

changeProcessName() protected méthode

Set new process name
protected changeProcessName ( )

cleanLog() protected méthode

Empty log queue
protected cleanLog ( )

closeStdStreams() protected méthode

Close std streams and open to /dev/null need some class properties
protected closeStdStreams ( )

defineJobExtractor() protected méthode

Fetch one task from array of tasks
protected defineJobExtractor ( &$jobs ) : mixed
Résultat mixed one task

defineJobs() abstract protected méthode

Extract current unprocessed jobs You can extract jobs from DB (DataProvider will be great), queue managers (ZMQ, RabbiMQ etc), redis and so on
abstract protected defineJobs ( ) : array
Résultat array with jobs

deletePid() protected méthode

Delete pid file
protected deletePid ( )

doJob() abstract protected méthode

Daemon worker body
abstract protected doJob ( $job ) : boolean
$job
Résultat boolean

flushLog() protected méthode

Empty log queue
protected flushLog ( $final = false )

getPidPath() public méthode

public getPidPath ( string $daemon = null ) : string
$daemon string
Résultat string

getProcessName() public méthode

public getProcessName ( $route = null ) : string
Résultat string

halt() protected méthode

Stop process and show or write message
protected halt ( $code, $message = null )
$code int -1|0|1
$message string

init() public méthode

Init function
public init ( )

initLogger() protected méthode

Adjusting logger. You can override it.
protected initLogger ( )

options() public méthode

Возвращает доступные опции
public options ( string $actionID ) : array
$actionID string
Résultat array

renewConnections() protected méthode

Renew connections
protected renewConnections ( )

runDaemon() final public méthode

Tasks runner
final public runDaemon ( string $job ) : boolean
$job string
Résultat boolean

signalHandler() final static public méthode

PCNTL signals handler
final static public signalHandler ( $signo, null $pid = null, null $status = null )
$signo
$pid null
$status null

stderr() public méthode

If in daemon mode - no write to console
public stderr ( string $string ) : integer
$string string
Résultat integer

stdout() public méthode

If in daemon mode - no write to console
public stdout ( string $string ) : boolean | integer
$string string
Résultat boolean | integer

Property Details

$currentJobs protected_oe static_oe property

[] array of running instances
protected static $currentJobs

$demonize public_oe property

boolean Run controller as Daemon
public $demonize

$isMultiInstance public_oe property

boolean allow daemon create a few instances
public $isMultiInstance

$logDir protected_oe property

protected $logDir

$maxChildProcesses public_oe property

int max daemon instances
public $maxChildProcesses

$memoryLimit protected_oe property

Memory limit for daemon, must bee less than php memory_limit
protected $memoryLimit

$parentPID protected_oe property

int main procces pid
protected $parentPID

$pidDir protected_oe property

protected $pidDir

$sleep protected_oe property

Delay between task list checking
protected $sleep