PHP Class PHPDaemon\Core\AppInstance

Author: Vasily Zorin ([email protected])
Inheritance: use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog
Datei anzeigen Open project: kakserpom/phpdaemon Class Usage Examples

Public Properties

Property Type Description
$config Related config section
$enableRPC Is RPC enabled?
$passphrase Optional passphrase
$ready Ready to run?
$requestClass Default class of incoming requests
$runOnDemand If true, it's allowed to be run without defined config section'

Protected Properties

Property Type Description
$name Instance name

Public Methods

Method Description
RPCall ( string $method, array $args ) : mixed Function handles incoming Remote Procedure Calls You can override it
__construct ( string $name = '' ) : void Application constructor
beginRequest ( object $req, object $upstream ) : object Create Request instance
broadcastCall ( string $method, array $args = [], callable $cb = null ) : boolean Send broadcast RPC You can override it
directCall ( integer $workerId, string $method, array $args = [], mixed $cb = null ) : boolean Send RPC, executed once in certain worker You can override it
getConfig ( ) : Section Returns a config section
getInstance ( string $name, boolean $spawn = true ) : AppInstance
getName ( ) : string Returns the instance name
handleRequest ( object $parent, object $upstream ) : object Handle the request
handleStatus ( integer $ret ) : boolean Handle the worker status
isEnabled ( ) : boolean Returns whether if this application is enabled
log ( string $message ) : void Log something
onConfigUpdated ( ) : void Called when worker is going to update configuration
onReady ( ) : void Called when the worker is ready to go
singleCall ( string $method, array $args = [], mixed $cb = null ) : boolean Send RPC, executed once in any worker You can override it

Protected Methods

Method Description
getConfigDefaults ( ) : boolean Function to get default config options from application Override to set your own
init ( ) : void Called when creates instance of the application
onShutdown ( $graceful = false ) : boolean Called when application instance is going to shutdown

Method Details

RPCall() public method

Function handles incoming Remote Procedure Calls You can override it
public RPCall ( string $method, array $args ) : mixed
$method string Method name
$args array Arguments
return mixed Result

__construct() public method

Application constructor
public __construct ( string $name = '' ) : void
$name string Instance name
return void

beginRequest() public method

Create Request instance
public beginRequest ( object $req, object $upstream ) : object
$req object Generic
$upstream object Upstream application instance
return object Request

broadcastCall() public method

Send broadcast RPC You can override it
public broadcastCall ( string $method, array $args = [], callable $cb = null ) : boolean
$method string Method name
$args array Arguments
$cb callable Callback
return boolean Success

directCall() public method

Send RPC, executed once in certain worker You can override it
public directCall ( integer $workerId, string $method, array $args = [], mixed $cb = null ) : boolean
$workerId integer Worker Id
$method string Method name
$args array Arguments
$cb mixed Callback
return boolean Success

getConfig() public method

Returns a config section
public getConfig ( ) : Section
return PHPDaemon\Config\Section

getConfigDefaults() protected method

Function to get default config options from application Override to set your own
protected getConfigDefaults ( ) : boolean
return boolean

getInstance() public static method

public static getInstance ( string $name, boolean $spawn = true ) : AppInstance
$name string Instance name
$spawn boolean If true, we spawn an instance if absent
return AppInstance

getName() public method

Returns the instance name
public getName ( ) : string
return string

handleRequest() public method

Handle the request
public handleRequest ( object $parent, object $upstream ) : object
$parent object Parent request
$upstream object Upstream application
return object Request

handleStatus() public method

Handle the worker status
public handleStatus ( integer $ret ) : boolean
$ret integer Status code
return boolean Result

init() protected method

Called when creates instance of the application
protected init ( ) : void
return void

isEnabled() public method

Returns whether if this application is enabled
public isEnabled ( ) : boolean
return boolean

log() public method

Log something
public log ( string $message ) : void
$message string Message
return void

onConfigUpdated() public method

Called when worker is going to update configuration
public onConfigUpdated ( ) : void
return void

onReady() public method

Called when the worker is ready to go
public onReady ( ) : void
return void

onShutdown() protected method

Called when application instance is going to shutdown
protected onShutdown ( $graceful = false ) : boolean
return boolean Ready to shutdown?

singleCall() public method

Send RPC, executed once in any worker You can override it
public singleCall ( string $method, array $args = [], mixed $cb = null ) : boolean
$method string Method name
$args array Arguments
$cb mixed Callback
return boolean Success

Property Details

$config public_oe property

Related config section
public $config

$enableRPC public_oe property

Is RPC enabled?
public $enableRPC

$name protected_oe property

Instance name
protected $name

$passphrase public_oe property

Optional passphrase
public $passphrase

$ready public_oe property

Ready to run?
public $ready

$requestClass public_oe property

Default class of incoming requests
public $requestClass

$runOnDemand public_oe static_oe property

If true, it's allowed to be run without defined config section'
public static $runOnDemand