Open
Description
Please answer these questions before submitting your issue.
- What did you do? If possible, provide a simple script for reproducing the error.
- Workerman设置Swoole作为事件循环
- Swoole版本为6.X
- 不开启iouring
- 响应一个大图片
满足以上条件后,会复现这个BUG
复现代码如下:
<?php
use Workerman\Connection\TcpConnection;
use Workerman\Events\Swoole;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';
$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->eventLoop = Swoole::class;
$http_worker->onMessage = function (TcpConnection $connection, Request $request) {
$response = (new Response())->withFile('./image_8M.png');
$connection->send($response);
};
Worker::runAll();
经调试,我猜可能和src/Protocols/Http.php
的第279行注册的onBufferDrain
事件有关,因为这个事件被并发执行了,导致同一时间$doWrite()
执行了多次。把249行的注释掉就没问题了。但是这个行为不合规,缓冲区功能将失效。
目前已测试过开启iouring是正常的,另外使用Select作为EventLoop也正常。
- What did you expect to see?
浏览器正常响应完整的图片
- What did you see instead?
浏览器只响应了一半的图片
- What version of Workerman are you using (show your
composer info
)?
workerman/coroutine 1.1.3 Workerman coroutine
workerman/webman-framework 2.1.2 High performance HTTP Service Framework.
workerman/workerman 5.1.3 An asynchronous event driven PHP framework for easily building fast, scalable network applications.
- What is your machine environment used (show your
uname -a
&php -v
&php -m
) ?
(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# uname -a
Linux MoxyuPC 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux
(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# php -v
PHP 8.4.7 (cli) (built: May 9 2025 10:58:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
swoole
sysvsem
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]