'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 最佳答案