PHP 8.3.21 Released!

EvPeriodic::__construct

(PECL ev >= 0.2.0)

EvPeriodic::__constructConstruye un objeto watcher EvPeriodic

Descripción

public EvPeriodic::__construct(
     float $offset ,
     string $interval ,
     callable $reschedule_cb ,
     callable $callback ,
     mixed $data = null ,
     int $priority = 0
)

Construye un objeto watcher EvPeriodic y lo inicia automáticamente. El método EvPeriodic::createStopped() crea un watcher periódico detenido.

Parámetros

offset

Ver los modos de operación del watcher periódico

interval

Ver los modos de operación del watcher periódico

reschedule_cb

Función de retrollamada Reschedule. Puede pasarse el valor null. Ver los modos de operación del watcher periódico

callback

Ver las funciones de retrollamada de los Watchers .

data

Datos personalizados para asociar con el watcher.

priority

Prioridad del Watcher

Ejemplos

Ejemplo #1 Temporizador periódico. Utilizando la retrollamada de replanificación

<?php
// Cada 10.5 segundos

function reschedule_cb ($watcher, $now) {
return
$now + (10.5. - fmod($now, 10.5));
}

$w = new EvPeriodic(0., 0., "reschedule_cb", function ($w, $revents) {
echo
time(), PHP_EOL;
});
Ev::run();
?>

Ejemplo #2 Temporizador periódico. Llamado cada 10.5 segundos

<?php
// Cada 10.5 segundos a partir de ahora
$w = new EvPeriodic(fmod(Ev::now(), 10.5), 10.5, NULL, function ($w, $revents) {
echo
time(), PHP_EOL;
});
Ev::run();
?>

Ejemplo #3 Watcher cada hora

<?php
$hourly
= EvPeriodic(0, 3600, NULL, function () {
echo
"una vez por hora\n";
});
?>

Ver también

add a note

User Contributed Notes 1 note

up
0
1187328898 at qq dot com
6 years ago
function reschedule_cb_10s ($watcher, $now) {
return $now + 10.;
}

//PHP7.0+版本不支持reschedule_cb模式
// PHP5.6测试通过
$w5 = new EvPeriodic(0.0, 0.0, "reschedule_cb_10s", function ($w, $revents) {
echo "w5:enter:", time(), PHP_EOL;
// sleep(3);
echo "w5:end:", time(), PHP_EOL;
});

Ev::run();
To Top