Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
laravelzh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
冯超鹏
laravelzh
Commits
2cd1f183
Commit
2cd1f183
authored
Jul 01, 2020
by
冯超鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新模块厂链接
parent
3082cb42
Pipeline
#62
failed with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
186 additions
and
0 deletions
+186
-0
chemicalswb.php
app/Console/Commands/chemicalswb.php
+93
-0
firewb.php
app/Console/Commands/firewb.php
+93
-0
No files found.
app/Console/Commands/chemicalswb.php
0 → 100644
View file @
2cd1f183
<?php
namespace
App\Console\Commands
;
use
App\Http\Controllers\Auth\SwooleCommandController
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Log
;
class
chemicalswb
extends
Command
{
public
$ws
;
private
$token
=
'zxc123456789ZXC'
;
public
$time
=
10
;
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'swoolechewb {action?}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'swoolechewb'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$action
=
$this
->
argument
(
'action'
);
switch
(
$action
)
{
case
'close'
:
break
;
default
:
$this
->
start
();
break
;
}
}
//开启WebSocket
public
function
start
()
{
$url
=
config
(
'public.swoolwebsocketurl'
);
$por
=
config
(
'public.swoolwebsocketurlpor'
);
$this
->
ws
=
new
\swoole_websocket_server
(
'0.0.0.0'
,
9507
);
//创建一个端口
$this
->
ws
->
set
(
array
(
'reactor_num'
=>
2
,
//reactor线程数
'worker_num'
=>
4
,
//worker进程数
'backlog'
=>
128
,
//Listen队列长度
'max_request'
=>
10
,
//最大连接
'daemonize'
=>
0
,
//守护进程
));
$this
->
ws
->
on
(
'open'
,
function
(
$ws
,
$request
)
{
// //链接成功
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
chemicals
(),
1
);
swoole_timer_tick
(
6000
,
function
(
$timerId
)
use
(
$ws
,
$request
)
{
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
chemicals
(),
1
);
});
});
//监听WebSocket消息事件
$this
->
ws
->
on
(
'message'
,
function
(
$ws
,
$frame
)
{
});
$this
->
ws
->
on
(
'request'
,
function
(
$request
,
$response
,
$from_id
,
$fd
)
{
});
//监听WebSocket连接关闭事件
$this
->
ws
->
on
(
'close'
,
function
(
$ws
,
$fd
)
{
echo
"client:
{
$fd
}
is closed
\n
"
;
swoole_timer_clear
(
$this
->
time
);
});
$this
->
ws
->
start
();
}
}
app/Console/Commands/firewb.php
0 → 100644
View file @
2cd1f183
<?php
namespace
App\Console\Commands
;
use
App\Http\Controllers\Auth\SwooleCommandController
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Log
;
class
firewb
extends
Command
{
public
$ws
;
private
$token
=
'zxc123456789ZXC'
;
public
$time
=
10
;
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'swoolefirewb {action?}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'swoolefirewb'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$action
=
$this
->
argument
(
'action'
);
switch
(
$action
)
{
case
'close'
:
break
;
default
:
$this
->
start
();
break
;
}
}
//开启WebSocket
public
function
start
()
{
$url
=
config
(
'public.swoolwebsocketurl'
);
$por
=
config
(
'public.swoolwebsocketurlpor'
);
$this
->
ws
=
new
\swoole_websocket_server
(
'0.0.0.0'
,
9508
);
//创建一个端口
$this
->
ws
->
set
(
array
(
'reactor_num'
=>
2
,
//reactor线程数
'worker_num'
=>
4
,
//worker进程数
'backlog'
=>
128
,
//Listen队列长度
'max_request'
=>
10
,
//最大连接
'daemonize'
=>
0
,
//守护进程
));
$this
->
ws
->
on
(
'open'
,
function
(
$ws
,
$request
)
{
// //链接成功
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
fire
(),
1
);
swoole_timer_tick
(
6000
,
function
(
$timerId
)
use
(
$ws
,
$request
)
{
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
fire
(),
1
);
});
});
//监听WebSocket消息事件
$this
->
ws
->
on
(
'message'
,
function
(
$ws
,
$frame
)
{
});
$this
->
ws
->
on
(
'request'
,
function
(
$request
,
$response
,
$from_id
,
$fd
)
{
});
//监听WebSocket连接关闭事件
$this
->
ws
->
on
(
'close'
,
function
(
$ws
,
$fd
)
{
echo
"client:
{
$fd
}
is closed
\n
"
;
swoole_timer_clear
(
$this
->
time
);
});
$this
->
ws
->
start
();
}
}
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