CakeFest 2024: The Official CakePHP Conference

EvPeriodic::__construct

(PECL ev >= 0.2.0)

EvPeriodic::__constructConstruit un objet watcher EvPeriodic

Description

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

Construit un objet watcher EvPeriodic et le démarre automatiquement. La méthode EvPeriodic::createStopped() crée un watcher périodique stoppé.

Liste de paramètres

offset

Voir les modes d'opération du watcher périodique

interval

Voir les modes d'opération du watcher périodique

reschedule_cb

Fonction de rappel Reschedule. Vous pouvez passer la valeur null. Voir les modes d'opération du watcher périodique

callback

Voir les fonctions de rappel des Watchers .

data

Données personnalisées à associer avec le watcher.

priority

Priorité du Watcher

Exemples

Exemple #1 Periodic timer. Use reschedule callback

<?php
// Toutes les 10.5 secondes

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();
?>

Exemple #2 Timer périodique. Appelé toutes les 10.5 secondes

<?php
// Toutes les 10.5 secondes à partir de maintenant
$w = new EvPeriodic(fmod(Ev::now(), 10.5), 10.5, NULL, function ($w, $revents) {
echo
time(), PHP_EOL;
});
Ev::run();
?>

Exemple #3 Watcher chaque heure

<?php
$hourly
= EvPeriodic(0, 3600, NULL, function () {
echo
"une fois par heure\n";
});
?>

Voir aussi

add a note

User Contributed Notes 1 note

up
0
1187328898 at qq dot com
5 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