PHP Class PHPPM\ProcessManager

Afficher le fichier Open project: php-pm/php-pm Class Usage Examples

Protected Properties

Свойство Type Description
$appBootstrap string
$appenv string | null
$bridge string
$concurrentRequestsPerWorker boolean This can lead to issues when the application does not support it (like when they operate on globals at the same time)
$controller PHPPM\React\Server
$controllerHost string
$debug boolean
$emergencyMode boolean Whether we are in the emergency mode or not. True means we need to close all workers due a fatal error and waiting for file changes to be able to restart workers.
$filesLastMTime
$filesLastMd5
$filesToTrack
$handledRequests integer Counter of handled clients.
$host string
$inReload boolean Whether the server is in the reload phase.
$inShutdown boolean
$index integer
$isRunning boolean Whether the server is up and thus creates new slaves when they die or not.
$lastWorkerErrorPrintBy null | integer
$logging boolean
$loop React\EventLoop\LibEventLoop | React\EventLoop\StreamSelectLoop
$maxRequests integer How many requests each worker is allowed to handle until it will be restarted.
$output Symfony\Component\Console\Output\OutputInterface
$phpCgiExecutable string Full path to the php-cgi executable. If not set, we try to determine the path automatically.
$port integer
$ports string[] $object_hash => port
$servingStatic boolean
$slaveCount integer
$slaves array
$tcpConnector React\SocketClient\TcpConnector
$timeout integer Timeout in seconds for master to worker connection.
$waitForSlaves boolean
$web React\Socket\Server

Méthodes publiques

Méthode Description
__construct ( Symfony\Component\Console\Output\OutputInterface $output, integer $port = 8080, string $host = '127.0.0.1', integer $slaveCount = 8 ) ProcessManager constructor.
getAppBootstrap ( ) : string
getAppEnv ( ) : string
getBridge ( ) : string
handleSigchld ( ) Handling zombie processes on SIGCHLD
isDebug ( ) : boolean
isLogging ( ) : boolean
isServingStatic ( ) : boolean
onSlaveConnection ( Connection $conn ) Handles data communication from slave -> master
onWeb ( Connection $incoming ) Handles incoming connections from $this->port. Basically redirects to a slave.
restartWorker ( ) Closes all slaves, so we automatically reconnect. Necessary when watched files have changed.
run ( ) Starts the main loop. Blocks.
setAppBootstrap ( string $appBootstrap )
setAppEnv ( string | null $appenv )
setBridge ( string $bridge )
setConcurrentRequestsPerWorker ( boolean $concurrentRequestsPerWorker )
setDebug ( boolean $debug )
setLogging ( boolean $logging )
setMaxRequests ( integer $maxRequests )
setPhpCgiExecutable ( string $phpCgiExecutable )
setServingStatic ( boolean $servingStatic )
shutdown ( ) Handles termination signals, so we can gracefully stop all servers.

Méthodes protégées

Méthode Description
bootstrapFailed ( Connection $conn ) Handles failed application bootstraps.
checkChangedFiles ( boolean $restartWorkers = true ) : boolean Checks if tracked files have changed. If so, restart all slaves.
commandFiles ( array $data, Connection $conn )
commandLog ( array $data, Connection $conn ) Prints logs.
commandReady ( array $data, Connection $conn ) A slave sent a ready commands which basically says that the slave bootstrapped successfully the application and is ready to accept connections.
commandRegister ( array $data, Connection $conn ) A slave sent a register command.
commandStatus ( array $data, Connection $conn ) A slave sent a status command.
getNextSlave ( $cb ) : integer Returns the next free slave. This method is async, so be aware of async calls between this call.
getPort ( Connection $conn ) : null | integer
isConnectionRegistered ( Connection $conn ) : boolean Whether the given connection is registered.
isHeaderEnd ( string $buffer ) : boolean Checks whether the end of the header is in $buffer.
newInstance ( integer $port ) Creates a new ProcessSlave instance.
replaceHeader ( string $header, string[] $headersToReplace ) : string Replaces or injects header

Method Details

__construct() public méthode

ProcessManager constructor.
public __construct ( Symfony\Component\Console\Output\OutputInterface $output, integer $port = 8080, string $host = '127.0.0.1', integer $slaveCount = 8 )
$output Symfony\Component\Console\Output\OutputInterface
$port integer
$host string
$slaveCount integer

bootstrapFailed() protected méthode

Handles failed application bootstraps.
protected bootstrapFailed ( Connection $conn )
$conn React\Socket\Connection

checkChangedFiles() protected méthode

This approach uses simple filemtime to check against modifications. It is using this technique because all other file watching stuff have either big dependencies or do not work under all platforms without installing a pecl extension. Also this way is interestingly fast and is only used when debug=true.
protected checkChangedFiles ( boolean $restartWorkers = true ) : boolean
$restartWorkers boolean
Résultat boolean

commandFiles() protected méthode

protected commandFiles ( array $data, Connection $conn )
$data array
$conn React\Socket\Connection

commandLog() protected méthode

Prints logs.
protected commandLog ( array $data, Connection $conn )
$data array
$conn React\Socket\Connection

commandReady() protected méthode

A slave sent a ready commands which basically says that the slave bootstrapped successfully the application and is ready to accept connections.
protected commandReady ( array $data, Connection $conn )
$data array
$conn React\Socket\Connection

commandRegister() protected méthode

A slave sent a register command.
protected commandRegister ( array $data, Connection $conn )
$data array
$conn React\Socket\Connection

commandStatus() protected méthode

A slave sent a status command.
protected commandStatus ( array $data, Connection $conn )
$data array
$conn React\Socket\Connection

getAppBootstrap() public méthode

public getAppBootstrap ( ) : string
Résultat string

getAppEnv() public méthode

public getAppEnv ( ) : string
Résultat string

getBridge() public méthode

public getBridge ( ) : string
Résultat string

getNextSlave() protected méthode

Returns the next free slave. This method is async, so be aware of async calls between this call.
protected getNextSlave ( $cb ) : integer
Résultat integer

getPort() protected méthode

protected getPort ( Connection $conn ) : null | integer
$conn React\Socket\Connection
Résultat null | integer

handleSigchld() public méthode

Handling zombie processes on SIGCHLD
public handleSigchld ( )

isConnectionRegistered() protected méthode

Whether the given connection is registered.
protected isConnectionRegistered ( Connection $conn ) : boolean
$conn React\Socket\Connection
Résultat boolean

isDebug() public méthode

public isDebug ( ) : boolean
Résultat boolean

isHeaderEnd() protected méthode

Checks whether the end of the header is in $buffer.
protected isHeaderEnd ( string $buffer ) : boolean
$buffer string
Résultat boolean

isLogging() public méthode

public isLogging ( ) : boolean
Résultat boolean

isServingStatic() public méthode

public isServingStatic ( ) : boolean
Résultat boolean

newInstance() protected méthode

Creates a new ProcessSlave instance.
protected newInstance ( integer $port )
$port integer

onSlaveConnection() public méthode

Handles data communication from slave -> master
public onSlaveConnection ( Connection $conn )
$conn React\Socket\Connection

onWeb() public méthode

Handles incoming connections from $this->port. Basically redirects to a slave.
public onWeb ( Connection $incoming )
$incoming React\Socket\Connection incoming connection from react

replaceHeader() protected méthode

Replaces or injects header
protected replaceHeader ( string $header, string[] $headersToReplace ) : string
$header string
$headersToReplace string[]
Résultat string

restartWorker() public méthode

Closes all slaves, so we automatically reconnect. Necessary when watched files have changed.
public restartWorker ( )

run() public méthode

Starts the main loop. Blocks.
public run ( )

setAppBootstrap() public méthode

public setAppBootstrap ( string $appBootstrap )
$appBootstrap string

setAppEnv() public méthode

public setAppEnv ( string | null $appenv )
$appenv string | null

setBridge() public méthode

public setBridge ( string $bridge )
$bridge string

setConcurrentRequestsPerWorker() public méthode

public setConcurrentRequestsPerWorker ( boolean $concurrentRequestsPerWorker )
$concurrentRequestsPerWorker boolean

setDebug() public méthode

public setDebug ( boolean $debug )
$debug boolean

setLogging() public méthode

public setLogging ( boolean $logging )
$logging boolean

setMaxRequests() public méthode

public setMaxRequests ( integer $maxRequests )
$maxRequests integer

setPhpCgiExecutable() public méthode

public setPhpCgiExecutable ( string $phpCgiExecutable )
$phpCgiExecutable string

setServingStatic() public méthode

public setServingStatic ( boolean $servingStatic )
$servingStatic boolean

shutdown() public méthode

Handles termination signals, so we can gracefully stop all servers.
public shutdown ( )

Property Details

$appBootstrap protected_oe property

protected string $appBootstrap
Résultat string

$appenv protected_oe property

protected string|null $appenv
Résultat string | null

$bridge protected_oe property

protected string $bridge
Résultat string

$concurrentRequestsPerWorker protected_oe property

This can lead to issues when the application does not support it (like when they operate on globals at the same time)
protected bool $concurrentRequestsPerWorker
Résultat boolean

$controller protected_oe property

protected Server,PHPPM\React $controller
Résultat PHPPM\React\Server

$controllerHost protected_oe property

protected string $controllerHost
Résultat string

$debug protected_oe property

protected bool $debug
Résultat boolean

$emergencyMode protected_oe property

Whether we are in the emergency mode or not. True means we need to close all workers due a fatal error and waiting for file changes to be able to restart workers.
protected bool $emergencyMode
Résultat boolean

$filesLastMTime protected_oe property

protected $filesLastMTime

$filesLastMd5 protected_oe property

protected $filesLastMd5

$filesToTrack protected_oe property

protected $filesToTrack

$handledRequests protected_oe property

Counter of handled clients.
protected int $handledRequests
Résultat integer

$host protected_oe property

protected string $host
Résultat string

$inReload protected_oe property

Whether the server is in the reload phase.
protected bool $inReload
Résultat boolean

$inShutdown protected_oe property

protected bool $inShutdown
Résultat boolean

$index protected_oe property

protected int $index
Résultat integer

$isRunning protected_oe property

Whether the server is up and thus creates new slaves when they die or not.
protected bool $isRunning
Résultat boolean

$lastWorkerErrorPrintBy protected_oe property

protected null|int $lastWorkerErrorPrintBy
Résultat null | integer

$logging protected_oe property

protected bool $logging
Résultat boolean

$loop protected_oe property

protected LibEventLoop,React\EventLoop|StreamSelectLoop,React\EventLoop $loop
Résultat React\EventLoop\LibEventLoop | React\EventLoop\StreamSelectLoop

$maxRequests protected_oe property

How many requests each worker is allowed to handle until it will be restarted.
protected int $maxRequests
Résultat integer

$output protected_oe property

protected OutputInterface,Symfony\Component\Console\Output $output
Résultat Symfony\Component\Console\Output\OutputInterface

$phpCgiExecutable protected_oe property

Full path to the php-cgi executable. If not set, we try to determine the path automatically.
protected string $phpCgiExecutable
Résultat string

$port protected_oe property

protected int $port
Résultat integer

$ports protected_oe property

$object_hash => port
protected string[] $ports
Résultat string[]

$servingStatic protected_oe property

protected bool $servingStatic
Résultat boolean

$slaveCount protected_oe property

protected int $slaveCount
Résultat integer

$slaves protected_oe property

protected array $slaves
Résultat array

$tcpConnector protected_oe property

protected TcpConnector,React\SocketClient $tcpConnector
Résultat React\SocketClient\TcpConnector

$timeout protected_oe property

Timeout in seconds for master to worker connection.
protected int $timeout
Résultat integer

$waitForSlaves protected_oe property

protected bool $waitForSlaves
Résultat boolean

$web protected_oe property

protected Server,React\Socket $web
Résultat React\Socket\Server