Skip to content

Commit 4e2d6b0

Browse files
committed
更新依赖包
1 parent 9edcb82 commit 4e2d6b0

File tree

8 files changed

+601
-1131
lines changed

8 files changed

+601
-1131
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": ">=8.1",
22-
"buexplain/netsvr-protocol-php": "^5.0.0",
22+
"buexplain/netsvr-protocol-php": "^5.1.0",
2323
"psr/container": "^2.0",
2424
"psr/log": "^2.0|^3.0"
2525
},

composer.lock

Lines changed: 452 additions & 1079 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Auxiliary/callback.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/Auxiliary/callback.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright 2023 buexplain@qq.com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
use NetsvrProtocol\ConnClose;
21+
use NetsvrProtocol\ConnOpen;
22+
use NetsvrProtocol\ConnOpenResp;
23+
24+
ini_set('display_errors', 'on');
25+
ini_set('display_startup_errors', 'on');
26+
error_reporting(E_ALL);
27+
date_default_timezone_set('Asia/Shanghai');
28+
require __DIR__ . '/../../vendor/autoload.php';
29+
30+
//php -S 0.0.0.0:6636 callback.php
31+
try {
32+
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
33+
switch ($path) {
34+
case '/':
35+
echo 'hello world';
36+
break;
37+
case '/onopen':
38+
onopen();
39+
break;
40+
case '/onclose':
41+
onclose();
42+
break;
43+
default:
44+
http_response_code(404);
45+
echo '404';
46+
break;
47+
}
48+
} catch (Throwable $e) {
49+
http_response_code(500);
50+
echo $e->getTraceAsString();
51+
}
52+
53+
/**
54+
* websocket连接打开的回调
55+
* @return void
56+
* @throws Exception
57+
*/
58+
function onopen(): void
59+
{
60+
$protobuf = file_get_contents('php://input');
61+
$cp = new ConnOpen();
62+
$cp->mergeFromString($protobuf);
63+
logger('conn open: ' . $cp->serializeToJsonString());
64+
$cpResp = new ConnOpenResp();
65+
$cpResp->setAllow(true);
66+
$cpResp->setData($cp->getUniqId());
67+
header('Content-Type: application/x-protobuf');
68+
http_response_code(200);
69+
echo $cpResp->serializeToString();
70+
}
71+
72+
/**
73+
* websocket连接关闭的回调
74+
* @return void
75+
* @throws Exception
76+
*/
77+
function onclose(): void
78+
{
79+
$protobuf = file_get_contents('php://input');
80+
$cp = new ConnClose();
81+
$cp->mergeFromString($protobuf);
82+
logger('conn close: ' . $cp->serializeToJsonString());
83+
header('Content-Type: application/x-protobuf');
84+
http_response_code(204);
85+
}
86+
87+
/**
88+
* 日志
89+
* @param string $message
90+
* @return void
91+
*/
92+
function logger(string $message): void
93+
{
94+
file_put_contents(
95+
"php://stdout",
96+
date('Y-m-d H:i:s') . ' --> ' . $message . PHP_EOL,
97+
FILE_APPEND
98+
);
99+
}

tests/Auxiliary/netsvr-607.toml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ HandlePattern = "/netsvr"
2222
AllowOrigin = []
2323
# websocket服务器读取客户端连接的超时时间,该时间段内,客户端连接没有发消息过来,则会超时,连接会被关闭,所以客户端连接必须在该时间间隔内发送心跳字符串
2424
ReadDeadline = "120s"
25+
# websocket服务器写入客户端连接的超时时间,该时间段内,没发送成功连接会被关闭
26+
SendDeadline = "1s"
2527
# 最大连接数,超过的会被拒绝
2628
MaxOnlineNum = 100000
2729
# io模式,0:IOModNonBlocking,1:IOModBlocking,2:IOModMixed,详细见:https://github.com/lesismal/nbio
@@ -32,28 +34,41 @@ MaxBlockingOnline = 10000
3234
ReceivePackLimit = 2097152
3335
# 往websocket连接写入时的消息类型,1:TextMessage,2:BinaryMessage
3436
SendMessageType = 1
35-
# 回调脚本文件,如果需要,最好配置绝对路径,不需要,请配置为空字符串
36-
CallbackScriptFile = "callback.go"
37+
# 连接打开与关闭的回调接口,如果没有,则不需要配置,否则会发送http的post调用,header头是application/x-protobuf,具体请求参数与返回要求,请参考internal/customer/callback/callback.go
38+
OnOpenCallbackApi = "http://127.0.0.1:6636/onopen"
39+
OnCloseCallbackApi = "http://127.0.0.1:6636/onclose"
40+
# 连接打开与关闭的回调接口超时时间
41+
CallbackApiDeadline = "3s"
3742
# tls配置
3843
TLSCert = ""
3944
TLSKey = ""
4045
# 心跳字符串,客户端连接必须定时发送该字符串,用于维持心跳
4146
HeartbeatMessage = "~6YOt5rW35piO~"
47+
# 压缩级别,区间是:[-2,9],0表示不压缩,具体见https://golang.org/pkg/compress/flate/
48+
CompressionLevel = 1
49+
# 固定窗口限流器的窗口大小
50+
LimitWindowSize = "1s"
51+
# 固定窗口限流器的窗口允许的最大请求数
52+
LimitWindowMaxRequests = 100
53+
# 固定窗口限流器的第0个窗口允许的最大请求数
54+
LimitZeroWindowMaxRequests = 1000
4255

4356
#业务进程的tcp服务器配置
4457
[Worker]
4558
# 监听的地址,ipv4:port,这个地址必须是内网ipv4地址,外网不允许访问,如果配置的是域名:端口,则会尝试获取域名对应的内网ipv4地址,并打印告警日志
4659
ListenAddress = "127.0.0.1:6071"
4760
# worker读取business连接的超时时间,该时间段内,business连接没有发消息过来,则会超时,连接会被关闭
4861
ReadDeadline = "120s"
49-
# worker发送给business连接的超时时间,该时间段内,没发送成功,business连接会被关闭
62+
# worker发送给business连接的超时时间,该时间段内,没发送成功且有部分写入,则business连接会被关闭
5063
SendDeadline = "10s"
5164
# business发送数据的大小限制(单位:字节),business发送了超过该限制的包,则连接会被关闭
5265
ReceivePackLimit = 2097152
5366
# 读取business发送数据的缓冲区大小(单位:字节)
5467
ReadBufferSize = 4096
5568
# worker发送给business的缓通道大小
5669
SendChanCap = 1024
70+
# worker发送给business的缓通道写入超时,默认是100毫秒,超过该时间还没写入,则丢弃消息并统计worker到business的失败次数
71+
SendChanDeadline = "100ms"
5772
# 心跳字符串,客户端连接必须定时发送该字符串,用于维持心跳
5873
HeartbeatMessage = "~6YOt5rW35piO~"
5974

@@ -65,9 +80,12 @@ HeartbeatMessage = "~6YOt5rW35piO~"
6580
# 3:统计客户连接的心跳次数
6681
# 4:统计客户数据转发到worker的次数
6782
# 5:统计客户数据转发到worker的字节数
68-
# 6:统计往客户写入数据次数
69-
# 7:统计往客户写入字节数
83+
# 6:统计往客户写入数据成功次数
84+
# 7:统计往客户写入数据成功字节数
7085
# 8:统计连接打开的限流次数
7186
# 9:统计客户消息限流次数
7287
# 10:统计worker到business的失败次数
73-
Item = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
88+
# 11:统计往客户写入数据失败次数
89+
# 12:统计往客户写入数据失败字节数
90+
# 13:统计连接消息限流次数
91+
Item = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

tests/Auxiliary/netsvr-608.toml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ HandlePattern = "/netsvr"
2222
AllowOrigin = []
2323
# websocket服务器读取客户端连接的超时时间,该时间段内,客户端连接没有发消息过来,则会超时,连接会被关闭,所以客户端连接必须在该时间间隔内发送心跳字符串
2424
ReadDeadline = "120s"
25+
# websocket服务器写入客户端连接的超时时间,该时间段内,没发送成功连接会被关闭
26+
SendDeadline = "1s"
2527
# 最大连接数,超过的会被拒绝
2628
MaxOnlineNum = 100000
2729
# io模式,0:IOModNonBlocking,1:IOModBlocking,2:IOModMixed,详细见:https://github.com/lesismal/nbio
@@ -32,28 +34,41 @@ MaxBlockingOnline = 10000
3234
ReceivePackLimit = 2097152
3335
# 往websocket连接写入时的消息类型,1:TextMessage,2:BinaryMessage
3436
SendMessageType = 1
35-
# 回调脚本文件,如果需要,最好配置绝对路径,不需要,请配置为空字符串
36-
CallbackScriptFile = "callback.go"
37+
# 连接打开与关闭的回调接口,如果没有,则不需要配置,否则会发送http的post调用,header头是application/x-protobuf,具体请求参数与返回要求,请参考internal/customer/callback/callback.go
38+
OnOpenCallbackApi = "http://127.0.0.1:6636/onopen"
39+
OnCloseCallbackApi = "http://127.0.0.1:6636/onclose"
40+
# 连接打开与关闭的回调接口超时时间
41+
CallbackApiDeadline = "3s"
3742
# tls配置
3843
TLSCert = ""
3944
TLSKey = ""
4045
# 心跳字符串,客户端连接必须定时发送该字符串,用于维持心跳
4146
HeartbeatMessage = "~6YOt5rW35piO~"
47+
# 压缩级别,区间是:[-2,9],0表示不压缩,具体见https://golang.org/pkg/compress/flate/
48+
CompressionLevel = 1
49+
# 固定窗口限流器的窗口大小
50+
LimitWindowSize = "1s"
51+
# 固定窗口限流器的窗口允许的最大请求数
52+
LimitWindowMaxRequests = 100
53+
# 固定窗口限流器的第0个窗口允许的最大请求数
54+
LimitZeroWindowMaxRequests = 1000
4255

4356
#业务进程的tcp服务器配置
4457
[Worker]
4558
# 监听的地址,ipv4:port,这个地址必须是内网ipv4地址,外网不允许访问,如果配置的是域名:端口,则会尝试获取域名对应的内网ipv4地址,并打印告警日志
4659
ListenAddress = "127.0.0.1:6081"
4760
# worker读取business连接的超时时间,该时间段内,business连接没有发消息过来,则会超时,连接会被关闭
4861
ReadDeadline = "120s"
49-
# worker发送给business连接的超时时间,该时间段内,没发送成功,business连接会被关闭
62+
# worker发送给business连接的超时时间,该时间段内,没发送成功且有部分写入,则business连接会被关闭
5063
SendDeadline = "10s"
5164
# business发送数据的大小限制(单位:字节),business发送了超过该限制的包,则连接会被关闭
5265
ReceivePackLimit = 2097152
5366
# 读取business发送数据的缓冲区大小(单位:字节)
5467
ReadBufferSize = 4096
5568
# worker发送给business的缓通道大小
5669
SendChanCap = 1024
70+
# worker发送给business的缓通道写入超时,默认是100毫秒,超过该时间还没写入,则丢弃消息并统计worker到business的失败次数
71+
SendChanDeadline = "100ms"
5772
# 心跳字符串,客户端连接必须定时发送该字符串,用于维持心跳
5873
HeartbeatMessage = "~6YOt5rW35piO~"
5974

@@ -65,9 +80,12 @@ HeartbeatMessage = "~6YOt5rW35piO~"
6580
# 3:统计客户连接的心跳次数
6681
# 4:统计客户数据转发到worker的次数
6782
# 5:统计客户数据转发到worker的字节数
68-
# 6:统计往客户写入数据次数
69-
# 7:统计往客户写入字节数
83+
# 6:统计往客户写入数据成功次数
84+
# 7:统计往客户写入数据成功字节数
7085
# 8:统计连接打开的限流次数
7186
# 9:统计客户消息限流次数
7287
# 10:统计worker到business的失败次数
73-
Item = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
88+
# 11:统计往客户写入数据失败次数
89+
# 12:统计往客户写入数据失败字节数
90+
# 13:统计连接消息限流次数
91+
Item = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
-3.66 MB
Binary file not shown.

tests/Cases/MainSocketManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function onClose(ConnClose $connClose): void
135135
//循环每个网关,并与之构建websocket连接
136136
foreach (TestHelper::$netsvrConfigForNetsvrSingle['netsvr'] as $config) {
137137
$client = new Client($config["ws"]);
138-
$client->setTimeout(5);
138+
$client->receive();
139139
$client->text($testMessage);
140140
$client->close();
141141
$client->disconnect();

0 commit comments

Comments
 (0)