(PECL ev >= 0.2.0)
EvTimer::createStopped — 建立已停止的 EvTimer 觀察器物件
$after
,$repeat
,$callback
,$data
= null
,$priority
= 0建立一個停止狀態的 EvTimer 監聽器物件。與 EvTimer::__construct() 不同,這個方法不會自動啟動監聽器。
成功時返回 EvTimer 監聽器物件。
範例 #1 監控 /var/log/messages 的變化。透過一秒的延遲避免遺漏更新
<?php
$timer = EvTimer::createStopped(0., 1.02, function ($w) {
$w->stop();
$stat = $w->data;
// 檔案最近一次變更後 1 秒
printf("目前大小:%ld\n", $stat->attr()['size']);
});
$stat = new EvStat("/var/log/messages", 0., function () use ($timer) {
// 重設計時器監聽器
$timer->again();
});
$timer->data = $stat;
Ev::run();
?>