tp6 think-worker 只要调用Db就报错

浏览:1082 发布日期:2020/09/23 分类:求助交流 关键字: thinkphp worker workerman
config已经配置自定义workerman服务
'worker_class' => '\app\afadmin\WorkerTask', // 自定义Workerman服务类名 支持数组定义多个服务

服务代码<?php
namespace app\afadmin;
use think\worker\Server;

class WorkerTask extends Server
{
    protected $socket = 'websocket://0.0.0.0:2347';

    public function __construct()
    {
        parent::__construct();
        // $this->onWorkerStart();
    }

    public function onWorkerStart($worker)
    {
        //每1运行一次
        // 只在id编号为0的进程上设置定时器,其它1、2、3号进程不设置定时器
        if($worker->id === 0)
        {
            \WorkerMan\Lib\Timer::add(1, function(){
                $db = new \think\facade\Db();
                $res = $db::name("af_goodsbatch")->limit(5)->select();
                dump($res);
            }, array(), true);
        }
    }

}
启动 php think worker:server
然后就报错,一直提示错误类数组引用错误[think\exception\ErrorException]                     
Trying to access array offset on value of type null
最佳答案
评论( 相关
后面还有条评论,点击查看>>