Example of passing custom data:
<?php
// Create and start timer firing after 2 seconds with custom data
$w1 = new EvTimer(2, 0, function ($w) {
echo "Custom data: $w->data\n";
echo "2 seconds elapsed\n";
}, 'abcd');
Ev::run();
?>
Running this will print out:
Custom data: abcd
2 seconds elapsed
Note that 'data' is a public property of the event EvWatcher class.
PHP.mk документација
EvTimer::__construct
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
evtimer.construct.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
evtimer.construct.php
EvTimer::__construct
Референца за `evtimer.construct.php` со подобрена типографија и навигација.
EvTimer::__construct
Класата EvPrepare
EvTimer::__construct — Constructs an EvTimer watcher object
= NULL
public
EvTimer::__construct(
float
float
callable
mixed
int
)
float
$after
,float
$repeat
,callable
$callback
,mixed
$data
= null
,int
$priority
= 0
)
Constructs an EvTimer watcher object.
Параметри
-
after -
Ја конфигурира временската рамка да се активира по
afterseconds. -
repeat -
Ако повторувањето е
0.0, тогаш автоматски ќе се запре откако ќе се достигне времето на истекување. Ако е позитивно, тогаш тајмерот автоматски ќе биде конфигуриран да се активира повторно на секои повтори секунди подоцна, додека не се запре рачно. -
callback - Константи за известување за грешки Повици за надзорници.
-
data - Прилагодени податоци поврзани со набљудувачот.
-
priority - Приоритет на набљудувачот
Примери
Пример #1 Едноставни тајмери
<?php
// Create and start timer firing after 2 seconds
$w1 = new EvTimer(2, 0, function () {
echo "2 seconds elapsed\n";
});
// Create and launch timer firing after 2 seconds repeating each second
// until we manually stop it
$w2 = new EvTimer(2, 1, function ($w) {
echo "is called every second, is launched after 2 seconds\n";
echo "iteration = ", Ev::iteration(), PHP_EOL;
// Stop the watcher after 5 iterations
Ev::iteration() == 5 and $w->stop();
// Stop the watcher if further calls cause more than 10 iterations
Ev::iteration() >= 10 and $w->stop();
});
// Create stopped timer. It will be inactive until we start it ourselves
$w_stopped = EvTimer::createStopped(10, 5, function($w) {
echo "Callback of a timer created as stopped\n";
// Stop the watcher after 2 iterations
Ev::iteration() >= 2 and $w->stop();
});
// Loop until Ev::stop() is called or all of watchers stop
Ev::run();
// Start and look if it works
$w_stopped->start();
echo "Run single iteration\n";
Ev::run(Ev::RUN_ONCE);
echo "Restart the second watcher and try to handle the same events, but don't block\n";
$w2->again();
Ev::run(Ev::RUN_NOWAIT);
$w = new EvTimer(10, 0, function() {});
echo "Running a blocking loop\n";
Ev::run();
echo "END\n";
?>Горниот пример ќе прикаже нешто слично на:
2 seconds elapsed is called every second, is launched after 2 seconds iteration = 1 is called every second, is launched after 2 seconds iteration = 2 is called every second, is launched after 2 seconds iteration = 3 is called every second, is launched after 2 seconds iteration = 4 is called every second, is launched after 2 seconds iteration = 5 Run single iteration Callback of a timer created as stopped Restart the second watcher and try to handle the same events, but don't block Running a blocking loop is called every second, is launched after 2 seconds iteration = 8 is called every second, is launched after 2 seconds iteration = 9 is called every second, is launched after 2 seconds iteration = 10 END
Види Исто така
- EvTimer::createStopped() - Креира EvTimer запрен набудувач објект
- EvPeriodic
- » ev_timer - relative and optionally repeating timeouts
- » Be smart about timeouts
Белешки од корисници 1 белешка
Jayesh Wadhwani ¶
12 години пред