Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
03f2914d
Commit
03f2914d
authored
Aug 27, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
d7a930a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
21 deletions
+4
-21
WorkermanWebSocketController.php
console/controllers/WorkermanWebSocketController.php
+4
-21
No files found.
console/controllers/WorkermanWebSocketController.php
View file @
03f2914d
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment