Skip to content

websocket 没有自动压缩发送数据 #5765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pz9042 opened this issue May 12, 2025 · 3 comments
Closed

websocket 没有自动压缩发送数据 #5765

pz9042 opened this issue May 12, 2025 · 3 comments

Comments

@pz9042
Copy link

pz9042 commented May 12, 2025

$server = new Swoole\WebSocket\Server("0.0.0.0", 9502);

$server->set([
    'websocket_compression' => true,
    'http_compression_min_length' => 100,
]);

$server ->on( 'message', function($server, $frame){
    $server ->push( $frame ->fd, base64_encode( random_bytes( 1020 ) ) );
});

抓包发现,reserved 是0,per-message compressed 为false,除非强制指定压缩 SWOOLE_WEBSOCKET_FLAG_COMPRESS | SWOOLE_WEBSOCKET_FLAG_FIN

@matyhtf
Copy link
Member

matyhtf commented May 13, 2025

执行一下 php --ri swoole 观察是否有 zlib、brotli、zstd 等压缩库的支持,另外客户端是否正确地发生了 accpet 响应

@pz9042
Copy link
Author

pz9042 commented May 13, 2025

执行一下 php --ri swoole 观察是否有 zlib、brotli、zstd 等压缩库的支持,另外客户端是否正确地发生了 accpet 响应

`swoole

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 6.0.0
Built => Feb 6 2025 19:37:08
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled`

我仔细看了下手册,swoole文档说,要自己针对消息加SWOOLE_WEBSOCKET_FLAG_COMPRESS 标志才会压缩。zlib库装了的,客户端请求和服务端响应都带了permessage-deflate

@matyhtf
Copy link
Member

matyhtf commented May 21, 2025

你的客户端是 Chrome 还是其他?HTTP 请求的 sec-websocket-extensions 头需要携带 permessage-deflate 才会启用压缩。

请将客户端完整 HTTP 头部发一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants