final class EvStat extends EvWatcher (View source)

Class EvStat

EvStat monitors a file system path for attribute changes. It calls stat() on that path in regular intervals (or when the OS signals it changed) and sees if it changed compared to the last time, invoking the callback if it did.

The path does not need to exist: changing from "path exists" to "path does not exist" is a status change like any other. The condition "path does not exist" is signified by the 'nlink' item being 0 (returned by EvStat::attr() method).

The path must not end in a slash or contain special components such as '.' or '..'. The path should be absolute: if it is relative and the working directory changes, then the behaviour is undefined.

Since there is no portable change notification interface available, the portable implementation simply calls stat() regularly on the path to see if it changed somehow. For this case a recommended polling interval can be specified. If one specifies a polling interval of 0.0 (highly recommended) then a suitable, unspecified default value will be used (which could be expected to be around 5 seconds, although this might change dynamically). libev will also impose a minimum interval which is currently around 0.1 , but that’s usually overkill.

This watcher type is not meant for massive numbers of EvStat watchers, as even with OS-supported change notifications, this can be resource-intensive.

Properties

bool $is_active from  EvWatcher
bool $is_pending from  EvWatcher
mixed $data from  EvWatcher
int $priority from  EvWatcher
float $interval
string $path

Methods

__construct(string $path, float $interval, callable $callback, mixed $data = null, int $priority = 0)

Constructs EvStat 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.

array
attr()

No description

array
prev()

No description

set(string $path, float $interval)

Configures the watcher.

bool
stat()

Initiates the stat call.

static EvStat
createStopped(string $path, float $interval, mixed $callback, mixed $data = null, int $priority = 0)

Create a stopped EvStat watcher object.

Details

__construct(string $path, float $interval, callable $callback, mixed $data = null, int $priority = 0)

Constructs EvStat watcher object.

Constructs EvStat watcher object and starts the watcher automatically.

Parameters

string $path

The path to wait for status changes on.

float $interval

Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

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.

array attr()

No description

Return Value

array

The values most recently detect by Ev (without actual stat'ing). See stat(2) man page for details.

array prev()

No description

Return Value

array

Just like EvStat::attr() , but returns the previous set of values.

set(string $path, float $interval)

Configures the watcher.

Parameters

string $path

The path to wait for status changes on.

float $interval

Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

bool stat()

Initiates the stat call.

Initiates the stat call(updates internal cache). It stats (using lstat) the path specified in the watcher and sets the internal cache to the values found.

Return Value

bool

TRUE if path exists. Otherwise FALSE.

final static EvStat createStopped(string $path, float $interval, mixed $callback, mixed $data = null, int $priority = 0)

Create a stopped EvStat watcher object.

Creates EvStat watcher object, but doesn't start it automatically (unlike EvStat::__construct()).

Parameters

string $path

The path to wait for status changes on.

float $interval

Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

mixed $callback
mixed $data
int $priority

Return Value

EvStat