PHP code example of esd / hashed-wheel-timer-plugin

1. Go to this page and download the library: Download esd/hashed-wheel-timer-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esd / hashed-wheel-timer-plugin example snippets


namespace app\Controller;

use ESD\Plugins\HashedWheelTimer\HashedWheelTimerRunnable;

class  TimerTask extends HashedWheelTimerRunnable{

    public function run()
    {
        /**
        //此处可根据延迟次数设置不同的延迟时间,比如支付通知失败
        if($this->getDelayTimes() <= 1){
            $this->setDelayTTL(10);
        }else if ($this->getDelayTimes() <= 2){
            $this->setDelayTTL(20);
        } else if ($this->getDelayTimes() <= 3){
            $this->setDelayTTL(30);
        } else if ($this->getDelayTimes() <= 4){
            $this->setDelayTTL(40);
        }else if ($this->getDelayTimes() <= 5){
            $this->setDelayTTL(40);
        }
         * **/


        //如果 return false 或者该类触发任意异常,系统会将此任务重新投递到下一次执行的位置。
        //如果不需要失败重试,需要 return true。可通过 getRetryTimes 获取重试次数进行判断
        //如超过5次则不再重试,直接return true。
        $this->getRetryTimes()


        //获取投递参数
        $params = $this->getParams();
        // TODO: Implement run() method.

        $this->info('run', $params);
        //如果执行 setDelayTTL , 需要return true ,否则会被重新投递到下一次执行的位置。
        return true;
    }