final class EvChild extends EvWatcher (View source)

Class EvChild

EvChild watchers trigger when the process receives a SIGCHLD in response to some child status changes (most typically when a child dies or exits). It is permissible to install an EvChild watcher after the child has been forked (which implies it might have already exited), as long as the event loop isn't entered(or is continued from a watcher), i.e. forking and then immediately registering a watcher for the child is fine, but forking and registering a watcher a few event loop iterations later or in the next callback invocation is not.

It is allowed to register EvChild watchers in the default loop only.

Properties

bool $is_active from  EvWatcher
bool $is_pending from  EvWatcher
mixed $data from  EvWatcher
int $priority from  EvWatcher
int $pid
int $rpid
int $rstatus

Methods

__construct(int $pid, bool $trace, callable $callback, mixed $data = null, int $priority = 0)

Constructs the EvChild watcher object.

int
clear()

Clear watcher pending status.

feed(int $revents)

Feeds the given revents set into the event loop.

getLoop()

Returns the loop responsible for the watcher.

invoke(int $revents)

Invokes the watcher callback with the given received events bit mask.

keepalive(bool $value = true)

Configures whether to keep the loop from returning.

setCallback(callable $callback)

Sets new callback for the watcher.

start()

Starts the watcher.

stop()

Stops the watcher.

static EvChild
createStopped(int $pid, bool $trace, mixed $callback, mixed $data = null, int $priority = 0)

Create instance of a stopped EvCheck watcher.

set(int $pid, bool $trace)

Configures the watcher

Details

__construct(int $pid, bool $trace, callable $callback, mixed $data = null, int $priority = 0)

Constructs the EvChild watcher object.

Call the callback when a status change for process ID pid (or any PID if pid is 0) has been received (a status change happens when the process terminates or is killed, or, when trace is TRUE, additionally when it is stopped or continued). In other words, when the process receives a SIGCHLD, Ev will fetch the outstanding exit/wait status for all changed/zombie children and call the callback.

It is valid to install a child watcher after an EvChild has exited but before the event loop has started its next iteration. For example, first one calls fork , then the new child process might exit, and only then an EvChild watcher is installed in the parent for the new PID .

You can access both exit/tracing status and pid by using the rstatus and rpid properties of the watcher object.

The number of PID watchers per PID is unlimited. All of them will be called.

The EvChild::createStopped() method doesn't start(activate) the newly created watcher.

Parameters

int $pid

Wait for status changes of process PID(or any process if PID is specified as 0 ).

bool $trace

If FALSE, only activate the watcher when the process terminates. Otherwise(TRUE) additionally activate the watcher when the process is stopped or continued.

callable $callback
mixed $data
int $priority

int clear()

Clear watcher pending status.

If the watcher is pending, this method clears its pending status and returns its revents bitset (as if its callback was invoked). If the watcher isn't pending it does nothing and returns 0.

Sometimes it can be useful to "poll" a watcher instead of waiting for its callback to be invoked, which can be accomplished with this function.

Return Value

int

In case if the watcher is pending, returns revents bitset as if the watcher callback had been invoked. Otherwise returns 0 .

feed(int $revents)

Feeds the given revents set into the event loop.

Feeds the given revents set into the event loop, as if the specified event had happened for the watcher.

Parameters

int $revents

Bit mask of watcher received events.

EvLoop getLoop()

Returns the loop responsible for the watcher.

Return Value

EvLoop

Event loop object responsible for the watcher.

invoke(int $revents)

Invokes the watcher callback with the given received events bit mask.

Parameters

int $revents

Bit mask of watcher received events.

keepalive(bool $value = true)

Configures whether to keep the loop from returning.

Configures whether to keep the loop from returning. With keepalive value set to FALSE the watcher won't keep Ev::run() / EvLoop::run() from returning even though the watcher is active.

Watchers have keepalive value TRUE by default.

Clearing keepalive status is useful when returning from Ev::run() / EvLoop::run() just because of the watcher is undesirable. It could be a long running UDP socket watcher or so.

Parameters

bool $value

With keepalive value set to FALSE the watcher won't keep Ev::run() / EvLoop::run() from returning even though the watcher is active.

setCallback(callable $callback)

Sets new callback for the watcher.

Parameters

callable $callback

void callback ([ object $watcher = NULL [, int $revents = NULL ]] )

start()

Starts the watcher.

Marks the watcher as active. Note that only active watchers will receive events.

stop()

Stops the watcher.

Marks the watcher as inactive. Note that only active watchers will receive events.

final static EvChild createStopped(int $pid, bool $trace, mixed $callback, mixed $data = null, int $priority = 0)

Create instance of a stopped EvCheck watcher.

The same as EvChild::__construct() , but doesn't start the watcher automatically.

Parameters

int $pid

Wait for status changes of process PID(or any process if PID is specified as 0 ).

bool $trace

If FALSE, only activate the watcher when the process terminates. Otherwise(TRUE) additionally activate the watcher when the process is stopped or continued.

mixed $callback
mixed $data
int $priority

Return Value

EvChild

set(int $pid, bool $trace)

Configures the watcher

Parameters

int $pid

Wait for status changes of process PID(or any process if PID is specified as 0 ).

bool $trace

If FALSE, only activate the watcher when the process terminates. Otherwise(TRUE) additionally activate the watcher when the process is stopped or continued.