已经运行很久的项目,今天突然出现发一条消息重复两条甚至多条消息

今天中午发生了这个事件,一直调试无果
大约持续了1个小时 又恢复正常,然后刚刚16点整的样子又出现了这个情况 并且现在还未成功恢复
workerman status正常 并且浏览器只发了一个包
同服务器的另外一个网站(基本上一样的代码同样的配置未出现标题中的情况)
用的端口1031 接收端口 1032 发送端口
这个是使用的代码
<?php
 
ini_set('memory_limit', '1024M');
 
use Workerman\Worker;
 
use Workerman\Lib\Timer;
 
use PHPSocketIO\SocketIO;
 
 
 
include __DIR__ . '/vendor/autoload.php';
 
 
 
$online_uid_list = array();
 
 
 
$sender_io = new SocketIO(1031);
 
$sender_io->count = 8;
 
 
 
$sender_io->on('connection', function($socket){
 
 
 
$socket->on('login', function ($data, $data2 = '') use($socket){
 
if(isset($socket->uid)) return;
 
 
 
if(isset($data['uid'])) $uid = $data['uid'];
 
else $uid = $data.'_'.$data2;
 
 
 
global $online_uid_list;
 
$uid = (string)$uid;
 
$online_uid_list[$uid] = array();
 
 
 
$socket->join($uid);
 
$socket->uid = $uid;
 
$socket->join('user');
 
send_visitor_count();
 
});
 
 
 
$socket->on('admin_login', function ($data) use($socket){
 
if(isset($socket->uid)) return;
 
 
 
$uid = $data['uid'];
 
$socket->join($uid);
 
$socket->uid = $uid;
 
$socket->join('admin');
 
});
 
 
 
$socket->on('send_my_tid', function ($tid) use($socket){
 
global $online_uid_list, $sender_io;
 
$online_uid_list[$socket->uid]['tid'] = $tid;
 
if($tid != '')
 
{
 
$socket->join('group_'.$tid);
 
}
 
});
 
 
 
$socket->on('where_i_from', function ($from) use($socket){
 
global $online_uid_list, $sender_io;
 
$online_uid_list[$socket->uid]['from'] = $from;
 
});
 
 
 
$socket->on('send_my_cid', function ($cid) use($socket){
 
global $online_uid_list, $sender_io;
 
$online_uid_list[$socket->uid]['cid'] = $cid;
 
if($cid != '')
 
{
 
$socket->join('group_'.$cid);
 
$sender_io->to('admin_'.$cid)->emit('update_visitor_list', $socket->uid);
 
}
 
else
 
{
 
$sender_io->to('admin')->emit('update_visitor_list', $socket->uid);
 
}
 
});
 
 
 
$socket->on('get_my_visitor', function ($cid) use($socket){
 
global $online_uid_list, $sender_io;
 
$result = array();
 
foreach($online_uid_list as $k => $v)
 
{
 
if( isset($v['cid']) AND ($v['cid'] == $cid OR $v['cid'] == '') ) $result[] = $k;
 
}
 
$sender_io->to('admin_'.$cid)->emit('update_visitor_list', join(',', $result));
 
});
 
 
 
$socket->on('get_all_visitor', function (){
 
global $online_uid_list, $sender_io;
 
$sender_io->to('admin')->emit('get_all_visitor', json_encode($online_uid_list));
 
});
 
 
 
$socket->on('get_visitor_count', function (){
 
send_visitor_count();
 
});
 
 
 
$socket->on('disconnect', function () use($socket){
 
if(!isset($socket->uid)) return;
 
global $online_uid_list;
 
 
 
$info = explode('_', $socket->uid);
 
if($info[0] != 'admin' AND isset($online_uid_list[$socket->uid]['cid']))
 
{
 
global $sender_io;
 
$sender_io->to('admin_'.$online_uid_list[$socket->uid]['cid'])->emit('visitor_leave', $socket->uid);
 
}
 
 
 
unset($online_uid_list[$socket->uid]);
 
 
 
send_visitor_count();
 
});
 
 
 
});
 
 
 
 
 
$sender_io->on('workerStart', function (){
 
$inner_http_worker = new Worker('http://0.0.0.0:1032');
 
$inner_http_worker->onMessage = function($http_connection, $data){
 
$_POST = $_POST ? $_POST : $_GET;
 
global $sender_io;
 
$to = isset($_POST['to']) ? $_POST['to'] : false;
 
if($to)
 
{
 
$to = explode('|', $to);
 
foreach($to as $v)
 
{
 
$sender_io->to($v)->emit($_POST['type'], $_POST['content']);
 
}
 
return $http_connection->send('ok');
 
}
 
else
 
{
 
            if(isset($_POST['type'])){
 
                $sender_io->emit($_POST['type'], $_POST['content']);
 
                return $http_connection->send('ok');
 
            }
 
}
 
return $http_connection->send('fail');
 
};
 
$inner_http_worker->listen();
 
 
 
});
 
 
 
function send_visitor_count()
 
{
 
global $online_uid_list, $sender_io;
 
$sender_io->to('user')->emit('get_visitor_count', count($online_uid_list));
 
}
 
 
 
 
 
if(!defined('GLOBAL_START'))
 
{
 
Worker::runAll();
 
}
 
已邀请:

要回复问题请先登录注册