class Events
{
static $receiver = null;
public static function onWorkerStart($businessWorker)
{
$reboot = Robot::getInstance();
}
同时在start_businesswork.php有如下测试代码
$inner_text_worker = new Worker('Text://0.0.0.0:5678');
$inner_text_worker->onMessage = function ($connection, $buffer) {
Robot::getInstance()
};
$inner_text_worker->listen();
Robot主要代码
protected function __construct()
{
echo "创建robot类\n";
}
public static function getInstance()
{
static $_instance = null;
if ($_instance === null) {
$_instance = new Robot();
}
return $_instance;
}
测试发现,Robot类创建了两次,说明数据不能在多个Event中共享?
开了两个进程?
两个进程的话会这样,是正常的
是的,开了4个进程,期望是在单机上面实现全局变量共享。
每个进程都会运行onWorkerStart,所以会执行多次。