// +---------------------------------------------------------------------- namespace crmeb\services; use Swoole\Timer; use think\facade\Log; class TimerService { public function tick($limit, $fn) { Timer::tick($limit, function () use ($fn) { try { $fn(); } catch (\Throwable $e) { Log::error('定时器报错[' . class_basename($this) . ']: ' . $e->getMessage()); } }); } }