PHP Class vyants\daemon\DaemonController

Author: Vladimir Yants ([email protected])
Inheritance: extends yii\console\Controller
显示文件 Open project: vyants/yii2-daemon Class Usage Examples

Public Properties

Property Type Description
$demonize boolean Run controller as Daemon
$isMultiInstance boolean allow daemon create a few instances
$maxChildProcesses int max daemon instances

Protected Properties

Property 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

Public Methods

Method 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

Protected Methods

Method 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

Method Description
loop ( ) : boolean Main Loop
writeConsole ( $message ) Show message in console

Method Details

__destruct() public method

public __destruct ( )

actionIndex() final public method

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

beforeAction() public method

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

changeProcessName() protected method

Set new process name
protected changeProcessName ( )

cleanLog() protected method

Empty log queue
protected cleanLog ( )

closeStdStreams() protected method

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

defineJobExtractor() protected method

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

defineJobs() abstract protected method

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
return array with jobs

deletePid() protected method

Delete pid file
protected deletePid ( )

doJob() abstract protected method

Daemon worker body
abstract protected doJob ( $job ) : boolean
$job
return boolean

flushLog() protected method

Empty log queue
protected flushLog ( $final = false )

getPidPath() public method

public getPidPath ( string $daemon = null ) : string
$daemon string
return string

getProcessName() public method

public getProcessName ( $route = null ) : string
return string

halt() protected method

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

init() public method

Init function
public init ( )

initLogger() protected method

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

options() public method

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

renewConnections() protected method

Renew connections
protected renewConnections ( )

runDaemon() final public method

Tasks runner
final public runDaemon ( string $job ) : boolean
$job string
return boolean

signalHandler() final static public method

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

stderr() public method

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

stdout() public method

If in daemon mode - no write to console
public stdout ( string $string ) : boolean | integer
$string string
return 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