Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
成刚
swoole-worker
Commits
5373c47d
Commit
5373c47d
authored
4 years ago
by
xielei
Browse files
Options
Download
Email Patches
Plain Diff
1
parent
82889592
main
2.0.1
2.0.0
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/zh-CN/06.Worker详解.md
+3
-3
docs/zh-CN/06.Worker详解.md
src/Cmd/RegisterWorker.php
+10
-6
src/Cmd/RegisterWorker.php
src/Worker.php
+1
-3
src/Worker.php
with
14 additions
and
12 deletions
+14
-12
docs/zh-CN/06.Worker详解.md
+
3
-
3
View file @
5373c47d
...
...
@@ -23,9 +23,6 @@ $worker = new Worker();
// 设置配置文件
$worker
->
config_file
=
__DIR__
.
'/config.php'
;
// 服务标签(供gateway自定义路由选择参考)
$worker
->
tag_list
=
[];
// 设置服务端参数 参考:http://wiki.swoole.com/#/server/setting
$worker
->
set
([
'log_file'
=>
__DIR__
.
'/log/worker.log'
,
...
...
@@ -60,6 +57,9 @@ return [
// 自动重载监听的文件或目录(配置文件已自动纳入)。
'reload_watch'
=>
[
__DIR__
.
'/event/'
],
// 服务标签(供gateway自定义路由选择参考)
'tag_list'
=>
[],
// worker事件文件
'worker_file'
=>
__DIR__
.
'/event/worker.php'
,
...
...
This diff is collapsed.
Click to expand it.
src/Cmd/RegisterWorker.php
+
10
-
6
View file @
5373c47d
...
...
@@ -32,11 +32,15 @@ class RegisterWorker implements CmdInterface
{
$res
=
self
::
decode
(
$buffer
);
$address
=
implode
(
':'
,
$conn
->
exportSocket
()
->
getpeername
());
$gateway
->
worker_list
[
$address
]
=
[
'tag_list'
=>
$res
[
'tag_list'
],
'pool'
=>
new
ConnectionPool
(
function
()
use
(
$conn
)
{
return
$conn
;
},
1
),
];
if
(
isset
(
$gateway
->
worker_list
[
$address
]))
{
$gateway
->
worker_list
[
$address
][
'tag_list'
]
=
$res
[
'tag_list'
];
}
else
{
$gateway
->
worker_list
[
$address
]
=
[
'tag_list'
=>
$res
[
'tag_list'
],
'pool'
=>
new
ConnectionPool
(
function
()
use
(
$conn
)
{
return
$conn
;
},
1
),
];
}
}
}
This diff is collapsed.
Click to expand it.
src/Worker.php
+
1
-
3
View file @
5373c47d
...
...
@@ -21,8 +21,6 @@ class Worker extends Service
public
$register_host
=
'127.0.0.1'
;
public
$register_port
=
9327
;
public
$tag_list
=
[];
protected
$process
;
protected
$inner_server
;
...
...
@@ -192,7 +190,7 @@ class Worker extends Service
$client
=
new
Client
(
$address
[
'lan_host'
],
$address
[
'lan_port'
]);
$client
->
onConnect
=
function
()
use
(
$client
,
$address
)
{
Service
::
debug
(
"connect to gateway
{
$address
[
'lan_host'
]
}
:
{
$address
[
'lan_port'
]
}
成功"
);
$client
->
send
(
Protocol
::
encode
(
RegisterWorker
::
encode
(
$this
->
tag_list
)));
$client
->
send
(
Protocol
::
encode
(
RegisterWorker
::
encode
(
Config
::
get
(
'
tag_list
'
,
[])
)));
$ping_buffer
=
Protocol
::
encode
(
pack
(
'C'
,
Ping
::
getCommandCode
()));
$client
->
timer_id
=
Timer
::
tick
(
30000
,
function
()
use
(
$client
,
$ping_buffer
,
$address
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets