final class EvPeriodic extends EvWatcher (View source)

Class EvPeriodic

Periodic watchers are also timers of a kind, but they are very versatile.

Unlike EvTimer, EvPeriodic watchers are not based on real time (or relative time, the physical time that passes) but on wall clock time (absolute time, calendar or clock). The difference is that wall clock time can run faster or slower than real time, and time jumps are not uncommon (e.g. when adjusting it).

EvPeriodic watcher can be configured to trigger after some specific point in time. For example, if an EvPeriodic watcher is configured to trigger "in 10 seconds" (e.g. EvLoop::now() + 10.0 , i.e. an absolute time, not a delay), and the system clock is reset to January of the previous year , then it will take a year or more to trigger the event (unlike an EvTimer , which would still trigger roughly 10 seconds after starting it as it uses a relative timeout).

As with timers, the callback is guaranteed to be invoked only when the point in time where it is supposed to trigger has passed. If multiple timers become ready during the same loop iteration then the ones with earlier time-out values are invoked before ones with later time-out values (but this is no longer true when a callback calls EvLoop::run() recursively).

Properties

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

Methods

__construct(float $offset, float $interval, null|callable $reschedule_cb, callable $callback, mixed $data = null, int $priority = 0)

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

void
again()

Simply stops and restarts the periodic watcher again.

float
at()

Returns the absolute time that this watcher is supposed to trigger next.

static EvPeriodic
createStopped(float $offset, float $interval, mixed $reschedule_cb, mixed $callback, mixed $data = null, int $priority = 0)

Create a stopped EvPeriodic watcher

void
set(float $offset, float $interval, null|callable $reschedule_cb = null)

Configures the watcher

Details

__construct(float $offset, float $interval, null|callable $reschedule_cb, callable $callback, mixed $data = null, int $priority = 0)

Constructs EvPeriodic watcher object.

Constructs EvPeriodic watcher object and starts it automatically. EvPeriodic::createStopped() method creates stopped periodic watcher.

Parameters

float $offset

When repeating, this contains the offset value, otherwise this is the absolute point in time (the offset value passed to EvPeriodic::set(), although libev might modify this value for better numerical stability).

float $interval

The current interval value. Can be modified any time, but changes only take effect when the periodic timer fires or EvPeriodic::again() is being called.

null|callable $reschedule_cb

If set, tt must return the next time to trigger, based on the passed time value (that is, the lowest time value larger than or equal to the second argument). It will usually be called just before the callback will be triggered, but might be called at other times, too.

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.

void again()

Simply stops and restarts the periodic watcher again.

Simply stops and restarts the periodic watcher again. This is only useful when attributes are changed.

Return Value

void

float at()

Returns the absolute time that this watcher is supposed to trigger next.

When the watcher is active, returns the absolute time that this watcher is supposed to trigger next. This is not the same as the offset argument to EvPeriodic::set() or EvPeriodic::__construct(), but indeed works even in interval mode.

Return Value

float

Rhe absolute time this watcher is supposed to trigger next in seconds.

final static EvPeriodic createStopped(float $offset, float $interval, mixed $reschedule_cb, mixed $callback, mixed $data = null, int $priority = 0)

Create a stopped EvPeriodic watcher

Create EvPeriodic object. Unlike EvPeriodic::__construct() this method doesn't start the watcher automatically.

Parameters

float $offset

When repeating, this contains the offset value, otherwise this is the absolute point in time (the offset value passed to EvPeriodic::set(), although libev might modify this value for better numerical stability).

float $interval

The current interval value. Can be modified any time, but changes only take effect when the periodic timer fires or EvPeriodic::again() is being called.

mixed $reschedule_cb

If set, tt must return the next time to trigger, based on the passed time value (that is, the lowest time value larger than or equal to the second argument). It will usually be called just before the callback will be triggered, but might be called at other times, too.

mixed $callback
mixed $data
int $priority

Return Value

EvPeriodic

void set(float $offset, float $interval, null|callable $reschedule_cb = null)

Configures the watcher

Parameters

float $offset

The same meaning as for {\EvPeriodic::__construct}

float $interval

The same meaning as for {\EvPeriodic::__construct}

null|callable $reschedule_cb

The same meaning as for {\EvPeriodic::__construct}

Return Value

void