Commit 03f2914d authored by shajiaiming's avatar shajiaiming

fix

parent d7a930a5
...@@ -77,10 +77,10 @@ class WorkermanWebSocketController extends Controller ...@@ -77,10 +77,10 @@ class WorkermanWebSocketController extends Controller
// 进程启动后设置一个每秒运行一次的定时器 // 进程启动后设置一个每秒运行一次的定时器
$wsWorker->onWorkerStart = function($worker) { $wsWorker->onWorkerStart = function ($worker) {
\Workerman\Lib\Timer::add(1, function()use($worker){ \Workerman\Lib\Timer::add(1, function () use ($worker) {
$time_now = time(); $time_now = time();
foreach($worker->connections as $connection) { foreach ($worker->connections as $connection) {
// 有可能该connection还没收到过消息,则lastMessageTime设置为当前时间 // 有可能该connection还没收到过消息,则lastMessageTime设置为当前时间
if (empty($connection->lastMessageTime)) { if (empty($connection->lastMessageTime)) {
$connection->lastMessageTime = $time_now; $connection->lastMessageTime = $time_now;
...@@ -95,13 +95,7 @@ class WorkermanWebSocketController extends Controller ...@@ -95,13 +95,7 @@ class WorkermanWebSocketController extends Controller
}; };
// Emitted when data received // Emitted when data received
$wsWorker->onMessage = function ($connection, $data) use ($wsWorker, $uids) { $wsWorker->onMessage = function ($connection, $data) {
if (!isset($connection->uid)) {
$connection->lastMessageTime = time();
$connection->uid = $data;
$wsWorker->uidConnections[$connection->uid] = $connection;
echo $connection->uid . ' 一共 ' . count($wsWorker->uidConnections[$connection->uid]) . PHP_EOL;
}
if ('binance' == $data) { if ('binance' == $data) {
$con = new \Workerman\Connection\AsyncTcpConnection("ws://stream.binance.com:9443/ws/!ticker@arr"); $con = new \Workerman\Connection\AsyncTcpConnection("ws://stream.binance.com:9443/ws/!ticker@arr");
$con->transport = 'ssl'; $con->transport = 'ssl';
...@@ -176,17 +170,6 @@ class WorkermanWebSocketController extends Controller ...@@ -176,17 +170,6 @@ class WorkermanWebSocketController extends Controller
} else { } else {
} }
}; };
$con->onClose = function ($con) use ($wsWorker) {
echo $con->id,"connection closed\n";
if(isset($con->uid))
{
// 连接断开时删除映射
unset($wsWorker->uidConnections[$con->uid]);
}
};
$con->onError = function ($con, $code, $msg) {
echo "Error code:$code msg:$msg\n";
};
$con->connect(); $con->connect();
} elseif ('okex' == $data) { } elseif ('okex' == $data) {
$connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER; $connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment