Class \Prado\Util\Behaviors\TCaptureForkLog
This captures the log of a child fork and sends it back to the parent thread.
When TProcessHelper::fork() is called, fxPrepareForFork
is raised before the fore and fxRestoreAfterFork
after the fork.
On fxPrepareForFork
, this class creates a socket pair. On fxRestoreAfterFork
,
The parent stores all child connections, and the child sends all log data to
the parent. The parent receives logs when processing logs.
Before sending logs, a child will receive any logs for its own child processes. When sending the final logs from the child, the socket is closed and the parent is flagged to close the connection.
When not the final processing of the logs, only the pending logs will be sent and received before returning. When Final, the parent will wait until all children processes have returned their logs.
Due to this class adding logs during the flushing of the logs
Attach this behavior to the TApplication class or object.
<behavior name="appSignals" AttachToClass="Prado\TApplication" class="Prado\Util\Behaviors\TApplicationSignals" PriorHandlerPriority="5" />
Class hierarchy
- \Prado\Util\Behaviors\TCaptureForkLog
- \Prado\Util\TBehavior implements IBehavior
- \Prado\Util\TBaseBehavior implements IBaseBehavior uses TPriorityPropertyTrait
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.3.0
public
|
configureForChildLogs(mixed $sender, array<string|int, mixed> $data) : mixed
The behavior call back for fxRestoreAfterFork that cleans the log and resets
the logger to send the log to the parent process. The Parent process stores
the child stream and pid and installs the onEndRequest handler to receive the
logs from the children forks.
|
public
|
dyAttachBehavior(string $name, IBaseBehavior $behavior, TCallChain $chain) : mixed
This is the singleton behavior. Only one instance of itself can be a behavior
of the owner.
|
public
|
events() : array<string|int, mixed>
Installs {@see self::generateConnection()} on fxPrepareForFork and
{@see self::configureForChildLogs()} on fxRestoreAfterFork.
|
public
|
generateConnection(mixed $sender, mixed $param) : array<string|int, mixed>|null
The behavior callback for fxPrepareForFork that creates a socket pair connection
between the parent process and child process before forking.
|
public
|
|
public
|
receiveLogsFromChildren([int|null $pid = null ][, bool $wait = true ]) : mixed
Receives logs from children forked processes and merges the logs with the current
application TLogger.
|
public
|
sendLogsToParent(mixed $logger, mixed $final) : mixed
First, Receives any logs from the children. If this instance is a child fork
then send the log to the parent process. If the call is final then the connection
to the parent is shutdown.
|
public
mixed
|
BEHAVIOR_NAME
|
'captureforklog'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |