ProcessForker
extends AbstractListener
in package
An execution loop listener that forks the process before executing code.
This is awesome, as the session won't die prematurely if user input includes a fatal error, such as redeclaring a class or function.
Table of Contents
- $savegame : mixed
- $up : mixed
- afterLoop() : mixed
- Clean up old savegames at the end of each loop iteration.
- afterRun() : mixed
- After the REPL session ends, send the scope variables back up to the main thread (if this is a child thread).
- beforeLoop() : mixed
- Create a savegame at the start of each loop iteration.
- beforeRun() : mixed
- Forks into a master and a loop process.
- isSupported() : bool
- Process forker is supported if pcntl and posix extensions are available.
- onExecute() : string|null
- Called before executing user code.
- onInput() : string|null
- Called on user input.
- createSavegame() : mixed
- Create a savegame fork.
- serializeReturn() : string
- Serialize all serializable return values.
Properties
$savegame
private
mixed
$savegame
$up
private
mixed
$up
Methods
afterLoop()
Clean up old savegames at the end of each loop iteration.
public
afterLoop(Shell $shell) : mixed
Parameters
- $shell : Shell
Return values
mixed —afterRun()
After the REPL session ends, send the scope variables back up to the main thread (if this is a child thread).
public
afterRun(Shell $shell) : mixed
Parameters
- $shell : Shell
Return values
mixed —beforeLoop()
Create a savegame at the start of each loop iteration.
public
beforeLoop(Shell $shell) : mixed
Parameters
- $shell : Shell
Return values
mixed —beforeRun()
Forks into a master and a loop process.
public
beforeRun(Shell $shell) : mixed
The loop process will handle the evaluation of all instructions, then return its state via a socket upon completion.
Parameters
- $shell : Shell
Return values
mixed —isSupported()
Process forker is supported if pcntl and posix extensions are available.
public
static isSupported() : bool
Return values
bool —onExecute()
Called before executing user code.
public
onExecute(Shell $shell, mixed $code) : string|null
Parameters
- $shell : Shell
- $code : mixed
Return values
string|null —User code override
onInput()
Called on user input.
public
onInput(Shell $shell, mixed $input) : string|null
Parameters
- $shell : Shell
- $input : mixed
Return values
string|null —User input override
createSavegame()
Create a savegame fork.
private
createSavegame() : mixed
The savegame contains the current execution state, and can be resumed in the event that the worker dies unexpectedly (for example, by encountering a PHP fatal error).
Return values
mixed —serializeReturn()
Serialize all serializable return values.
private
serializeReturn(array<string|int, mixed> $return) : string
A naïve serialization will run into issues if there is a Closure or SimpleXMLElement (among other things) in scope when exiting the execution loop. We'll just ignore these unserializable classes, and serialize what we can.
Parameters
- $return : array<string|int, mixed>