swoole定時器莫名的自動關閉了,但是所有進程都正常運行?

來源:互聯網
上載者:User
1.使用swoole的tick建立了定時器,每3s去資料庫查詢需要發送的資訊並進行發送,但是運行幾天后定時器就不跑了,定時器是在啟動worker進程時

function onWorkerStart(swoole_server $serv, $worker_id)    {                $this->loger->write_log('info',"Work_id " . $worker_id . " start \n");        //如果當前啟動並執行進程是task進程        if($worker_id < $serv->setting['worker_num'])         {            //開始執行任務            $serv->task($worker_id);        }             //添加定時器 只在第一個worker啟動時建立一個定時器 來定時檢索有沒有要推送的訊息        if($worker_id == 0)        {            //建立定時器            $timer = $serv->tick(3000,function ($timer_id){                $db = new DBO(config_item('mall_db_config'));                //擷取所有未發送的推送訊息                $query_param = array('limit'=>100,'order'=>'createon asc','where'=>'msg_status = 0');                $msgs = $db->select('t_msg_push',                            array('id','mall_id','member_id','vpl','in_time','out_time','park_code',                                'pay_points','park_duration','residual_points','msg_type'),                            $query_param                        );                if(!empty($msgs))                {                    push_msg($msgs,$db);                }                else                {                    simple_log('No message to send.');                }                //關閉資料庫連接                $db->close();            });        }    }

回複內容:

1.使用swoole的tick建立了定時器,每3s去資料庫查詢需要發送的資訊並進行發送,但是運行幾天后定時器就不跑了,定時器是在啟動worker進程時

function onWorkerStart(swoole_server $serv, $worker_id)    {                $this->loger->write_log('info',"Work_id " . $worker_id . " start \n");        //如果當前啟動並執行進程是task進程        if($worker_id < $serv->setting['worker_num'])         {            //開始執行任務            $serv->task($worker_id);        }             //添加定時器 只在第一個worker啟動時建立一個定時器 來定時檢索有沒有要推送的訊息        if($worker_id == 0)        {            //建立定時器            $timer = $serv->tick(3000,function ($timer_id){                $db = new DBO(config_item('mall_db_config'));                //擷取所有未發送的推送訊息                $query_param = array('limit'=>100,'order'=>'createon asc','where'=>'msg_status = 0');                $msgs = $db->select('t_msg_push',                            array('id','mall_id','member_id','vpl','in_time','out_time','park_code',                                'pay_points','park_duration','residual_points','msg_type'),                            $query_param                        );                if(!empty($msgs))                {                    push_msg($msgs,$db);                }                else                {                    simple_log('No message to send.');                }                //關閉資料庫連接                $db->close();            });        }    }
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.