1--TEST-- 2swoole_timer: timer in master (base) 3--SKIPIF-- 4<?php require __DIR__ . '/../include/skipif.inc'; ?> 5--FILE-- 6<?php 7require __DIR__ . '/../include/bootstrap.php'; 8$pm = new ProcessManager; 9$pm->setWaitTimeout(-1); 10$pm->parentFunc = function () use ($pm) { 11 if (IS_MAC_OS) { 12 $pm->kill(); 13 } 14}; 15$pm->childFunc = function () use ($pm) { 16 $server = new Swoole\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); 17 $server->set([ 18 'worker_num' => 1, 19 'log_file' => '/dev/null', 20 ]); 21 $server->on('start', function (Swoole\Server $server) use ($pm) { 22 echo "start\n"; 23 $id = Swoole\Timer::tick(100, function () { 24 echo "timer 1\n"; 25 }); 26 Swoole\Timer::after(300, function () use ($id, $server, $pm) { 27 echo "timer 2\n"; 28 Swoole\Timer::clear($id); 29 Swoole\Timer::tick(50, function ($id) use ($server, $pm) { 30 static $i = 0; 31 echo "timer 3\n"; 32 $i++; 33 if ($i > 4) { 34 echo "end\n"; 35 Swoole\Timer::clear($id); 36 $pm->wakeup(); 37 $server->shutdown(); 38 } 39 }); 40 }); 41 }); 42 $server->on('receive', function () { }); 43 $server->start(); 44}; 45$pm->childFirst(); 46$pm->run(); 47?> 48--EXPECT-- 49start 50timer 1 51timer 1 52timer 1 53timer 2 54timer 3 55timer 3 56timer 3 57timer 3 58timer 3 59end 60