Timer

For some tasks that are delayed or periodically executed, you need to use a timer. The Swoft framework encapsulates a set of timer operations that developers can use directly. Remember to use the Svoft framework to encapsulate them. If you use Swoole directly, it will cause a series of problems due to the context.

2.0.5+ support, the timer must be packaged using the Swoft framework, do not use the Swoole directly.

Tick

Perform a task periodically, using the following examples:

 $paramOne = 1;
$paramTwo = 1;
\Swoft\Timer::tick(1, function ($paramOne, $paramTwo) {
    // To to something
}, $paramOne, $paramTwo); 

\Swoft\Timer::tick detailed parameters:

  • The time in milliseconds that $msec is executed, in milliseconds
  • $callback callback function
  • The argument passed by $params will be passed to the callback function intact.

After

Execute the task for a while, using the following examples:

 $paramOne = 1;
$paramTwo = 1;
\Swoft\Timer::after(1, function ($paramOne, $paramTwo) {
    // To to something
}, $paramOne, $paramTwo); 
  • $msec delay time in milliseconds
  • $callback callback function
  • The argument passed by $params will be passed to the callback function intact.
/docs/2.x/en/common/timer.html
progress-bar