Releases: swoole/swoole-src
Releases · swoole/swoole-src
v5.1.6
🐛 Bug Fixes:
- Fixed the issue where
Swoole\Http\Response::end()
returnsnull
. @NathanFreeman - Fixed the problem where the mutex lock of
Swoole\Table
could not be used before the process exits. @matyhtf - Fixed the failure of
Swoole\Server::stop()
caused by using named parameters. @matyhtf - Fixed the issue where the
runtime tcp
module did not support dynamically enabling SSL encryption. @matyhtf - Fixed the
Fatal error
issue caused by the timeout feature ofPHP
inZTS
mode. @matyhtf - Fixed the problem where
Swoole\Coroutine::getaddrinfo()
method could lead to SIGSEGV. @matyhtf - Fixed the issue where the HTTP client running for a long time resulted in incorrect timeout settings. @matyhtf
⛔ Warning:
- The
v5.1.x
version does not supportPHP-8.4
. If you want to useSwoole
withPHP-8.4
, please use the6.0
version.
😊 Thank you:
- Thank you for your contributions to
Swoole v5.1.6
. Wishing everyone good health, all the best, and smooth work.
🐛 Bug修复:
- 修复
Swoole\Http\Response::end()
返回null
的问题。 @NathanFreeman - 修复进程退出之前会导致
Swoole\Table
的互斥锁无法使用的问题。 @matyhtf - 修复使用命名参数导致
Swoole\Server::stop()
执行失败的问题。 @matyhtf - 修复
runtime tcp
模块不支持动态开启SSL加密的问题。 @matyhtf - 修复
PHP
在ZTS
模式下的超时特性引起的Fatal error
问题。 @matyhtf - 修复Swoole\Coroutine::getaddrinfo()方法会导致SIGSEGV的问题。 @matyhtf
- 修复http客户端长时间运行导致超时时间不正确的问题。 @matyhtf
⛔ 注意:
v5.1.*
版本不支持PHP-8.4
,如果想在PHP-8.4
中使用Swoole
,请使用v6.0
版本。
😊 致谢:
- 感谢你们为
Swoole v5.1.6
做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
v6.0.0-rc1
✨ New Features:
- Added
non-blocking, reentrant coroutine mutex lock
, which can be used between processes/threads without blocking them. @NathanFreeman Swoole\Coroutine\Socket::getOption()
supports theTCP_INFO
option. @matyhtfSwoole\Client
synchronous blocking client supportshttp
proxy. @matyhtf- Added asynchronous non-blocking
TCP/UDP/Unix socket
clientSwoole\Async\Client
. @matyhtf - Optimized the
Swoole\Redis\Server::format()
method to support zero-copy memory, supportredis
nested structure. @matyhtf
🐛 Bug Fixes:
- Fixed
Fatal error
issue caused byPHP-8.4
'stimeout
feature in ZTS mode. @matyhtf - Fixed compatibility issue with the
exit()
hook
function forPHP-8.4
. @remicollet - Fixed the issue where
Swoole\Thread::getNativeId()
did not work incygwin
. @matyhtf - Fixed the issue causing
SIGSEGV
inSwoole\Coroutine::getaddrinfo()
method. @matyhtf - Fixed the issue where the runtime TCP module did not support dynamically enabling SSL encryption. @matyhtf
- Fixed the issue where the HTTP client had an incorrect timeout after running for a long time. @matyhtf
- Fixed the problem where the mutex lock of
Swoole\Table
could not be used before the process exited. @matyhtf - Fixed the failure of
Swoole\Server::stop()
when using named parameters. @matyhtf - Fixed the crash caused by
Swoole\Thread\Map::toArray()
not copying the key. @matyhtf - Fixed the issue of being unable to delete nested numeric keys in
Swoole\Thread\Map
. @matyhtf
⭐️ Kernel Optimization:
- Multi-thread mode
SWOOLE_THREAD
supports restarting worker threads. @matyhtf - Multi-thread mode
SWOOLE_THREAD
supports starting timers in theManager
thread. @matyhtf - Compatible with the
curl
extension ofPHP-8.4
. @matyhtf @NathanFreeman - Refactored
iouring
. @matyhtf @NathanFreeman - Optimized timers so that synchronous processes do not depend on signals. @matyhtf
- Optimized the
Swoole\Coroutine\System::waitSignal()
method to allow listening to multiple signals simultaneously. @matyhtf
😊 Thank you:
- Thank you for your contributions to
Swoole v6.0.0
. Wishing everyone good health, happiness, and success in your work.
⛔️ Warning:
- This version is a
pre-release
and should not be used in production environments, only in testing environments.
✨️ 新特性:
- 新增`非阻塞,可重入的互斥协程锁”,该锁可以在进程间/线程间使用,且不会阻塞进程/线程。 @NathanFreeman
Swoole\Coroutine\Socket::getOption()
支持了TCP_INFO
选项。 @matyhtfSwoole\Client
同步阻塞客户端支持http
代理。 @matyhtf- 新增异步非阻塞的
TCP/UDP/Unixsocket
客户端Swoole\Async\Client
。 @matyhtf - 优化
Swoole\Redis\Server::format
()方法,支持内存零拷贝,支持redis
嵌套结构。 @matyhtf
🐛 Bug修复:
- 修复因为
PHP-8.4
在ZTS模式下的超时
特性引起的Fatal error
问题。 @matyhtf - 修复
PHP-8.4
的exit()
函数hook
。 @remicollet - 修复
Swoole\Thread::getNativeId()
在cygwin
无法工作的问题。 @matyhtf - 修复
Swoole\Coroutine::getaddrinfo()
方法会导致SIGSEGV
的问题。 @matyhtf - 修复
runtime tcp
模块不支持动态开启SSL加密的问题。 @matyhtf - 修复http客户端长时间运行导致超时时间不正确的问题。 @matyhtf
- 修复进程退出之前会导致
Swoole\Table
的互斥锁无法使用的问题。 @matyhtf - 修复使用命名参数导致
Swoole\Server::stop()
执行失败的问题。 @matyhtf - 修复
Swoole\Thread\Map::toArray()
函数未复制key
导致崩溃的问题。 @matyhtf - 修复
Swoole\Thread\Map
无法删除嵌套的数字键的问题。 @matyhtf
⭐️ 内核优化:
- 异步
Server
多线程模式支持重启工作线程。 @matyhtf - 异步
Server
多线程模式支持在Manager
线程中开启定时器。 @matyhtf - 兼容
PHP-8.4
的curl
扩展。 @matyhtf @NathanFreeman - 重构
iouring
。 @matyhtf @NathanFreeman - 优化定时器,使同步进程不依赖于信号。 @matyhtf
- 优化
Swoole\Coroutine\System::waitSignal()
方法,允许同时监听多个信号。 @matyhtf
😊 致谢:
- 感谢你们为
Swoole v6.0.0
做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
⛔️ 警告:
- 目前该版本是预发布版本,禁止在生产环境中使用,只能用于测试环境。
v5.1.5
🐛 Bug Fixes:
- Fix the need to use
zend_ini_parse_quantity
to parse string numbers for PHP versions greater than 8.2. @matyhtf - Fix an occasional resource unavailability issue when coroutineizing
pdo_pgsql
. @NathanFreeman - Fix header file reference issues when coroutineizing
pdo_pgsql
. @NathanFreeman - Fix incorrect relative path checks to avoid bypassing path validation. @matyhtf
- Fix incorrect concurrency count caused by process restarts in high-concurrency environments. @matyhtf
⭐️ Kernel Optimization:
- Sync some related code for
php8.3 curl
. @NathanFreeman - Fix core test errors in the
process
module. @NathanFreeman - In
SWOOLE_BASE
mode, all connections should be closed during thePHP RSHUTDOWN
phase. @matyhtf - Optimize kernel code. @matyhtf
😊 Thank you
- Thank you for your contribution to Swoole v6.0.0. Wish you good health, all the best, and smooth work.
🐛 Bug修复:
- 修复php版本大于8.2,需要使用
zend_ini_parse_quantity
解析字符串数字。 @matyhtf - 修复
pdo_pgsql
协程化的时候,偶发资源不可用的问题。 @NathanFreeman - 修复
pdo_pgsql
协程化的时候,头文件引用问题。 @NathanFreeman - 修复不正确的相对路径检查,以避免绕过路径验证。 @matyhtf
- 修复高并发环境下,进程重启会导致并发数不正确。 @matyhtf
⭐️ 内核优化:
- 同步
php8.3 curl
的一些相关代码。 @NathanFreeman - 修复
process
模块核心测试错误。 @NathanFreeman - 在
SWOOLE_BASE
模式下,所有的连接都应该在PHP RSHUTDOWN
阶段都被关闭。 @matyhtf - 优化内核代码。 @matyhtf
😊 致谢
- 感谢你们为Swoole v5.1.5做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
v6.0.0-beta
✨ New Feature:
- Added
Swoole\Thread\Map::find()
method. @matyhtf - Added
Swoole\Thread\ArrayList::find()
method. @matyhtf - Added
Swoole\Thread\ArrayList::offsetUnset()
method. @matyhtf - Added
Swoole\Process::getAffinity()
method. @matyhtf - Added
Swoole\Thread::setName()
method. @matyhtf - Added
Swoole\Thread::setAffinity()
method. @matyhtf - Added
Swoole\Thread::getAffinity()
method. @matyhtf - Added
Swoole\Thread::setPriority()
method. @matyhtf - Added
Swoole\Thread::getPriority()
method. @matyhtf - Added
Swoole\Thread::gettid()
method. - The file asynchronous engine
iouring
supports multi-threaded polling modeIORING_SETUP_SQPOLL
. @NathanFreeman - Added
iouring_workers
to modify the number ofiouring
threads. @NathanFreeman - Added
iouring_flags
to support modifying theiouring
working mode. @NathanFreeman - Added
Swoole\Thread\Barrier
for multi-thread synchronization barrier. @matyhtf - Added new function and class to set cookies. @matyhtf @NathanFreeman
New Cookie API
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($pm) {
$cookie = new Swoole\Http\Cookie();
$cookie->withName('key1')
->withValue('val1')
->withExpires(time() + 84600)
->withPath('/')
->withDomain('id.test.com')
->withSecure(true)
->withHttpOnly(true)
->withSameSite('None')
->withPriority('High')
->withPartitioned(true);
$response->setCookie($cookie);
$response->end("<h1>Hello Swoole. #" . rand(1000, 9999) . "</h1>");
});
🐛 Bug Fixed:
- Fixed the dynamic property issue in
Swoole\Http2\Request
. @guandeng - Fixed the occasional resource unavailability issue in the
pgsql
coroutine client. @NathanFreeman - Fixed the issue of 503 errors due to not resetting related parameters during process restart. @matyhtf
- Fixed the inconsistency between
$request->server['request_method']
and$request->getMethod()
whenHTTP2
is enabled. @matyhtf - Fixed incorrect
content-type
when uploading files. @matyhtf - Fixed code errors in the
http2
coroutine client. @matyhtf - Fixed the missing
worker_id
property inSwoole\Server
. @cjavad - Fixed errors related to
brotli
inconfig.m4
. @fundawang - Fixed the invalid
Swoole\Http\Response::create
under multi-threading. @matyhtf - Fixed compilation errors in the
macos
environment. @matyhtf - Fixed the issue of threads not being able to exit safely. @matyhtf
- Fixed the issue where the static variable for response time returned by
Swoole\Http\Response
in multi-threaded mode was not generated separately for each thread. @matyhtf @NathanFreeman
⭐️ Kernel Optimization:
- Upgraded the Oracle database version for CI testing. @gvenzl
- Refactored and optimized the underlying related code of
swoole
. @matyhtf - Optimized the underlying logic of
sendfile
. @matyhtf - Optimized parameter parsing. @matyhtf
- Replaced
PHP_DEF_HAVE
withAC_DEFINE_UNQUOTED
inconfig.m4
. @petk - Optimized the logic related to
heartbeat
,shutdown
, andstop
for the server in multi-threaded mode. @matyhtf - Optimized to avoid linking
librt
whenglibc
version is greater than 2.17. @matyhtf - Enhanced the HTTP client to accept duplicate request headers. @matyhtf
- Optimized
Swoole\Http\Response::write()
. @matyhtf Swoole\Http\Response::write()
can now send HTTP/2 protocol. @matyhtf- Compatible with
PHP 8.4
. @matyhtf @NathanFreeman - Added the ability for asynchronous writing at the underlying socket level. @matyhtf
- Optimized
Swoole\Http\Response
. @NathanFreeman - Improved underlying error messages. @matyhtf
- Supported sharing PHP native sockets in multi-threaded mode. @matyhtf
- Optimized static file service and fixed static file path error issues. @matyhtf
❌ Deprecated:
- Removed
Swoole\Coroutine\System::fread()
,Swoole\Coroutine\System::fwrite()
, andSwoole\Coroutine\System::fgets()
methods.
😊 Thank you
- Thank you for your contribution to Swoole v6.0.0. Wish you good health, all the best, and smooth work.
✨ 新特性:
- 新增
Swoole\Thread\Map::find()
方法。 @matyhtf - 新增
Swoole\Thread\ArrayList::find()
方法。 @matyhtf - 新增
Swoole\Thread\ArrayList::offsetUnset()
方法。 @matyhtf - 新增
Swoole\Process::getAffinity()
方法。 @matyhtf - 新增
Swoole\Thread::setName()
方法。 @matyhtf - 新增
Swoole\Thread::setAffinity()
方法。 @matyhtf - 新增
Swoole\Thread::getAffinity()
方法。 @matyhtf - 新增
Swoole\Thread::setPriority()
方法。 @matyhtf - 新增
Swoole\Thread::getPriority()
方法。 @matyhtf - 新增
Swoole\Thread::gettid()
方法。 - 文件异步引擎
iouring
支持多线程轮询模式IORING_SETUP_SQPOLL
。 @NathanFreeman - 新增
iouring_workers
修改iouring
线程数。 @NathanFreeman - 新增
iouring_flags
支持修改iouring
工作模式。 @NathanFreeman - 增加
Swoole\Thead\Barrier
多线程同步屏障。@matyhtf - 增加新的设置cookie的函数。 @matyhtf @NathanFreeman
🐛 Bug修复:
- 修复
Swoole\Http2\Request
动态属性问题。 @guandeng - 修复
pgsql
协程客户端偶发资源不可用的问题。 @NathanFreeman - 修复进程重启,没有重置相关参数导致503错误的问题。@matyhtf
- 修复开启
HTTP2
时,$request->server['request_method'] 与 $request->getMethod() 的结果不一致。 @matyhtf - 修复上传文件时,不正确的
content-type
。 @matyhtf - 修复
http2
协程客户端的代码错误。 @matyhtf - 修复
Swoole\Server
缺少属性worker_id
的问题。 @cjavad - 修复
config.m4
有关brotli
错误的问题。 @fundawang - 修复 多线程下
Swoole\Http\Response::create
无效。 @matyhtf - 修复
macos
环境下编译错误。 @matyhtf - 修复线程无法安全退出的问题。 @matyhtf
- 修复多线程模式下,
Swoole\Http\Response
返回响应时间的静态变量没有各个线程各自生成一份的问题。 @matyhtf @NathanFreeman
⭐️ 内核优化:
- 升级CI测试的oracle数据库版本。 @gvenzl
- 重构优化
swoole
底层相关代码。 @matyhtf - 优化底层
sendfile
的相关逻辑。 @matyhtf - 优化参数解析。 @matyhtf
config.m4
中用AC_DEFINE_UNQUOTED
替换PHP_DEF_HAVE
。 @petk- 优化多线程模式下,server的
heartbeat
,shutdown
和stop
的相关逻辑。 @matyhtf - 优化
glibc
版本高于2.17时,不需要链接librt
。 @matyhtf - 加强
http
客户端可以接受重复的请求头。 @matyhtf - 优化
Swoole\Http\Response::write()
。 @matyhtf Swoole\Http\Response::write()
现在可以发送http2
协议。 @matyhtf- 兼容
PHP8.4
。 @matyhtf @NathanFreeman - 增加底层
socket
异步写入的能力。 @matyhtf - 优化
Swoole\Http\Response
。 @NathanFreeman - 优化底层错误信息。 @matyhtf
- 多线程模式下,支持共享php原生
socket
。 @matyhtf - 优化静态文件服务,修复静态文件路径错误问题。 @matyhtf
❌ 废弃:
- 移除
Swoole\Coroutine\System::fread()
,Swoole\Coroutine\System::fwrite()
和Swoole\Coroutine\System::fgets()
方法
😊 致谢
- 感谢你们为Swoole v6.0.0做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
v5.1.4
🐛 Bug Fixed:
- Fix broken build with GCC 14. @remicollet
- Fix could not send SSL negotiation packet(Resource temporarily unavailable). @NathanFreeman
- Fix the issue where certain critical parameters of
Swoole\Server
are not reset to 0 during process restart. @NathanFreeman - Fix the problem where
Swoole\Http\Request::getMethod()
returns the incorrect request method whenHTTP2
is enabled. @matyhtf
💪 Optimization:
- Optimize
Swoole\Http\Response::end()
. Response data larger than 16K will be sent directly through the socket, while data smaller than or equal to 16K will be copied to the buffer first before being sent out via the socket. @NathanFreeman
😊 Thank you
- Thank you for your contribution to Swoole v5.1.4. Wish you good health, all the best, and smooth work.
🐛 Bug 修复:
- 修复无法在
GCC 14
编译Swoole的问题。 @remicollet - 修复
pdo_pgsql
在协程化时会抛出资源不可用的错误。 @NathanFreeman - 修复
Swoole\Server
进程重启时,某些关键参数不会重置为0。 @NathanFreeman - 修复开启
HTTP2
时,Swoole\Http\Request::getMethod()
返回错误的请求方法的问题。 @matyhtf
💪 优化:
- 优化
Swoole\Http\Response::end()
,大于16K的响应数据将通过套接字直接发送,小于等于16K的数据会先拷贝在buffer中,再通过套接字发送出去。 @NathanFreeman
😊 致谢
- 感谢你们为Swoole v5.1.4做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
v6.0.0-alpha
✨ New Feature:
Swoole
supports multi-threading mode. WhenPHP
is inZTS
mode andSwoole
is compiled with--enable-swoole-thread
, the multi-threading mode can be utilized.- Added a new thread management class
Swoole\Thread
. @matyhtf - Introduced thread lock
Swoole\Thread\Lock
. @matyhtf - Added thread atomic counter
Swoole\Thread\Atomic
,Swoole\Thread\Atomic\Long
. @matyhtf - Added safe concurrent containers
Swoole\Thread\Map
,Swoole\Thread\ArrayList
,Swoole\Thread\Queue
. @matyhtf - File asynchronous operations support
iouring
as the underlying engine. Installingliburing
and compilingSwoole
with--enable-iouring
enables asynchronous operations for functions likefile_get_contents
,file_put_contents
,fopen
,fclose
,fread
,fwrite
,mkdir
,unlink
,fsync
,fdatasync
,rename
,fstat
,lstat
,filesize
throughiouring
. @matyhtf @NathanFreeman - Upgraded
Boost Context
to version 1.84. Now, Loongson CPUs can also support coroutines. @NathanFreeman
📖 example:
- How to create threads
use Swoole\Thread;
$args = Thread::getArguments(); // If it is main thread, the $args is empty; if it is a child thread, the $args is not empty.
$c = 4;
if (empty($args)) {
# main thread
for ($i = 0; $i < $c; $i++) {
$threads[] = new Thread(__FILE__, $i);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
}
} else {
# child thread x 4
echo "Thread #" . $args[0] . "\n";
while (1) {
sleep(1);
file_get_contents('https://www.baidu.com/');
}
}
- Thread + Server (Asynchronous Style)
use Swoole\Process;
use Swoole\Thread;
use Swoole\Http\Server;
$http = new Server("0.0.0.0", 9503, SWOOLE_THREAD);
$http->set([
'worker_num' => 2,
'task_worker_num' => 3,
'bootstrap' => __FILE__,
// sharing data between threads through `init_arguments`.
'init_arguments' => function () use ($http) {
$map = new Swoole\Thread\Map;
return [$map];
}
]);
$http->on('Request', function ($req, $resp) use ($http) {
$resp->end('hello world');
});
$http->on('pipeMessage', function ($http, $srcWorkerId, $msg) {
echo "[worker#" . $http->getWorkerId() . "]\treceived pipe message[$msg] from " . $srcWorkerId . "\n";
});
$http->addProcess(new Process(function () {
echo "user process, id=" . Thread::getId();
sleep(2000);
}));
$http->on('Task', function ($server, $taskId, $srcWorkerId, $data) {
var_dump($taskId, $srcWorkerId, $data);
return ['result' => uniqid()];
});
$http->on('Finish', function ($server, $taskId, $data) {
var_dump($taskId, $data);
});
$http->on('WorkerStart', function ($serv, $wid) {
// Retrieve shared data passed by `init_arguments` in the configuration using `Swoole\Thread::getArguments()`.
var_dump(Thread::getArguments(), $wid);
});
$http->on('WorkerStop', function ($serv, $wid) {
var_dump('stop: T' . Thread::getId());
});
$http->start();
- Thread + Coroutine
use Swoole\Thread;
$args = Thread::getArguments(); // If it is main thread, the $args is empty; if it is a child thread, the $args is not empty.
$c = 4;
if (empty($args)) {
# main thread
for ($i = 0; $i < $c; $i++) {
$threads[] = new Thread(__FILE__, $i);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
}
} else {
# child thread x 4
echo "Thread #" . $args[0] . "\n";
Co\run(function() {
while (1) {
sleep(1);
Co\go(function () {
file_get_contents('https://www.baidu.com/');
});
}
});
}
🐛 Bug Fixed:
- Fixed the issue where installation via
pecl
was not possible. @remicollet - Fixed the bug where setting
keepalive
was not possible forSwoole\Coroutine\FastCGI\Client
. @NathanFreeman - Fixed the issue where exceeding the
max_input_vars
would throw an error, causing the process to restart repeatedly. @NathanFreeman - Fixed unknown issues caused by using
Swoole\Event::wait()
within a coroutine. @matyhtf - Fixed the problem where
proc_open
does not support pty in coroutine mode. @matyhtf - Fixed segmentation fault issues with
pdo_sqlite
on PHP 8.3. @NathanFreeman - Fixed unnecessary warnings during the compilation of
Swoole
. @Appla @NathanFreeward - Fixed the error thrown by zend_fetch_resource2_ex when
STDOUT/STDERR
are already closed. @Appla @matyhtf - Fixed ineffective
set_tcp_nodelay
configuration. @matyhtf - Fixed the occasional unreachable branch issue during file upload. @NathanFreeman
- Fixed the problem where setting
dispatch_func
would cause PHP's internals to throw errors. @NathanFreeman - Fixed the deprecation of AC_PROG_CC_C99 in autoconf >= 2.70. @petk
- Capture exceptions when thread creation fails. @matyhtf
- Fixed the undefined problem with
_tsrm_ls_cache
. @jingjingxyk - Fixed the fatal compile error with
GCC 14
. @remicollet
⭐️ Kernel optimization:
- Removed unnecessary checks for
socket structs
. @petk - Upgraded Swoole Library. @deminy
- Added support for status code 451 in
Swoole\Http\Response
. @abnegate - Synchronized
file
operation code across different PHP versions. @NathanFreeman - Synchronized
pdo
operation code across different PHP versions. @NathanFreeman - Optimized the code for
Socket::ssl_recv()
. @matyhtf - Improved config.m4; some configurations can now set library locations via
pkg-config
. @NathanFreeman - Optimized the use of dynamic arrays during
request header parsing
. @NathanFreeman - Optimized file descriptor
fd
lifecycle issues in multi-threading mode. @matyhtf - Optimized some fundamental coroutine logic. @matyhtf
❌ Deprecated:
- No longer supports
PHP 8.0
. - No longer supports
Swoole\Coroutine\MySQL
coroutine client. - No longer supports
Swoole\Coroutine\Redis
coroutine client. - No longer supports
Swoole\Coroutine\PostgreSQL
coroutine client.
⚠ Warning:
Swoole-v6.0.0-alpha
is a test version and cannot be used in any production environment; it is for testing purposes only.
😊 Thank you
- Thank you for your contribution to Swoole v6.0.0. Wish you good health, all the best, and smooth work.
✨ 新特性:
Swoole
支持多线程模式,当php
是zts
模式,编译Swoole
时开启--enable-swoole-thread
时,就能使用多线程模式。- 新增线程管理类
Swoole\Thread
。 @matyhtf - 新增线程锁
Swoole\Thread\Lock
。 @matyhtf - 新增线程原子计数
Swoole\Thread\Atomic
,Swoole\Thread\Atomic\Long
。 @matyhtf - 新增安全并发容器
Swoole\Thread\Map
,Swoole\Thread\ArrayList
,Swoole\Thread\Queue
。 @matyhtf - 文件异步操作支持
iouring
作为底层引擎,安装了liburing
和编译Swoole
时开启--enable-iouring
,file_get_contents
,file_put_contents
,fopen
,fclose
,fread
,fwrite
,mkdir
,unlink
,fsync
,fdatasync
,rename
,fstat
,lstat
,filesize
这些函数的异步操作将会由iouring
实现。 @matyhtf @NathanFreeman - 升级
Boost Context
版本到1.84。现在,龙芯CPU也能够支持协程了。 @NathanFreeman
📖 示例:
- 创建线程
use Swoole\Thread;
$args = Thread::getArguments(); // 如果是主线程,$args 为空,如果是子线程,$args 不为空
$c = 4;
if (empty($args)) {
# 主线程
for ($i = 0; $i < $c; $i++) {
$threads[] = new Thread(__FILE__, $i);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
}
} else {
# 子线程
echo "Thread #" . $args[0] . "\n";
while (1) {
sleep(1);
file_get_contents('https://www.baidu.com/');
}
}
- 线程 + 服务端(异步风格)
use Swoole\Process;
use Swoole\Thread;
use Swoole\Http\Server;
$http = new Server("0.0.0.0", 9503, SWOOLE_THREAD);
$http->set([
'worker_num' => 2,
'task_worker_num' => 3,
'bootstrap' => __FILE__,
// 通过init_arguments实现线程间的数据共享。
'init_arguments' => function () use ($http) {
$map = new Swoole\Thread\Map;
return [$map];
}
]);
$http->on('Request', function ($req, $resp) use ($http) {
$resp->end('hello world');
});
$http->on('pipeMessage', function ($http, $srcWorkerId, $msg) {
echo "[worker#" . $http->getWorkerId() . "]\treceived pipe message[$msg] from " . $srcWorkerId . "\n";
});
$http->addProcess(new Process(function () {
echo "user process, id=" . Thread::getId();
sleep(2000);
}));
$http->on('Task', function ($server, $taskId, $srcWorkerId, $data) {
var_dump($taskId, $srcWorkerId, $data);
return ['result' => uniqid()];
});
$http->on('Finish', function ($server, $taskId, $data) {
var_dump($taskId, $data);
});
$http->on('WorkerStart', function ($serv, $wid) {
// 通过Swoole\Thread::getArguments()获取配置中的init_arguments传递的共享数据
var_dump(Thread::getArguments(), $wid);
});
$http->on('WorkerStop', function ($serv, $wid) {
var_dump('stop: T' . Thread::getId());
});
$http->start();
- Thread + Coroutine 在线程中使用协程
use Swoole\Thread;
$args = Thread::getArguments(); // If it is main thread, the $args is empty; if it is a child thread, the $args is not empty.
$c = 4;
if (empty($args)) {
# main thread
for ($i = 0; $i < $c; $i++) {
$threads[] = new Thread(__FILE__, $i);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
}
} else {
# child thread x 4
echo "Thread #" . $args[0] . "\n";
Co\run(function() {
while (1) {
sleep(1);
Co\go(function () {
file_get_contents('https://www.baidu.com/');
});
}
});
}
🐛 Bug修复:
- 修复无法通过
pecl
安装的问题。 @remicollet - 修复
Swoole\Coroutine\FastCGI\Client
客户端无法设置keepalive。 @NathanFreeman - 修复请求参数超过
max_input_vars
时会抛出错误导致进程不断重启的问题。 @NathanFreeman - 修复在协程中使用
Swoole\Event::wait()
导致的未知问题。 @matyhtf - 修复
proc_open
在协程化的时候不支持pty的问题。 @matyhtf - 修复
pdo_sqlite
在PHP8.3会出现段错误的问题。 @NathanFreeman - 修复编译
Swoole
时的无用警告。 @Appla @NathanFreeman - 修复如果
STDOUT/STDERR
已经关闭时,底层调用zend_fetch_resource2_ex会抛出错误。 @Appla @matyhtf - 修复无效的
set_tcp_nodelay
配置。 @matyhtf - 修复文件上传的时...
v5.1.3
🐛 Bug Fixed:
- Fix the problem of being unable to install through
pecl
. @remicollet - Fix the issue of
Swoole\Coroutine\FastCGI\Client
client being unable to set keepalive. @NathanFreeman - Fix the issue of process continuously restarting due to error thrown when request parameters exceed
max_input_vars
. @NathanFreeman - Fix the unknown issue caused by using
Swoole\Event::wait()
in a coroutine. @matyhtf - Fix the issue of
proc_open
not supporting pty when used in a coroutine. @matyhtf - Fix the segmentation fault issue in
pdo_sqlite
on PHP 8.3. @NathanFreeman - Fix the unnecessary warning when compiling Swoole. @Appla @NathanFreeman
- Fix the error thrown when calling zend_fetch_resource2_ex on closed
STDOUT/STDERR
. @Appla @matyhtf - Fix the invalid
set_tcp_nodelay
configuration. @matyhtf - Fix the occasional unreachable branch issue triggered during file uploads. @NathanFreeman
- Fix the issue causing PHP core to throw errors when
dispatch_func
is set. @NathanFreeman - Fix the obsolete warning of AC_PROG_CC_C99 in autoconf >= 2.70 version. @petk
⭐️ Kernel optimization:
- Remove unnecessary checks for
socket structs
. @petk - Upgrade the
Swoole library
. @deminy - Add support for status code 451 in
Swoole\Http\Response
. @abnegate - Synchronize
file
operation code across different versions of PHP. @NathanFreeman - Synchronize
PDO
operation code across different versions of PHP. @NathanFreeman - Optimize the code for
Socket::ssl_recv()
function. @matyhtf - Optimized config.m4 by allowing some configurations to set dependency library locations using
pkg-config
. @NathanFreeman - Optimize the issue with using dynamic arrays when
parsing request headers
. @NathanFreeman
😊 Thank you
- Thank you for your contribution to Swoole v5.1.3. Wish you good health, all the best, and smooth work.
🐛 Bug修复:
- 修复无法通过
pecl
安装的问题。 @remicollet - 修复
Swoole\Coroutine\FastCGI\Client
客户端无法设置keepalive。 @NathanFreeman - 修复请求参数超过
max_input_vars
时会抛出错误导致进程不断重启的问题。 @NathanFreeman - 修复在协程中使用
Swoole\Event::wait()
导致的未知问题。 @matyhtf - 修复
proc_open
在协程化的时候不支持pty的问题。 @matyhtf - 修复
pdo_sqlite
在PHP8.3会出现段错误的问题。 @NathanFreeman - 修复编译
Swoole
时的无用警告。 @Appla @NathanFreeman - 修复如果
STDOUT/STDERR
已经关闭时,底层调用zend_fetch_resource2_ex会抛出错误。 @Appla @matyhtf - 修复无效的
set_tcp_nodelay
配置。 @matyhtf - 修复文件上传的时候偶尔会触发不可达的分支问题。 @NathanFreeman
- 修复设置了
dispatch_func
,会导致php底层抛出错误的问题。 @NathanFreeman - 修复AC_PROG_CC_C99在autoconf >= 2.70版本中已过时。 @petk
⭐️ 内核优化:
- 移除对
socket structs
的无用检查。 @petk - 升级swoole Library。 @deminy
Swoole\Http\Response
增加对451状态码的支持。 @abnegate- 同步PHP不同版本的
文件
操作代码。 @NathanFreeman - 同步PHP不同版本的
pdo
操作代码。 @NathanFreeman - 优化
Socket::ssl_recv()
的代码。 @matyhtf - 优化了config.m4,一些配置可以通过
pkg-config
设置依赖库位置。 @NathanFreeman - 优化
解析请求头
的时候使用动态数组的问题 。 @NathanFreeman
😊 致谢
- 感谢你们为Swoole v5.1.3做出的贡献,祝愿大家身体健康,万事如意,工作顺利。
v5.1.2
- Added support for embed sapi @matyhtf
- Fixed compatibility with PHP 8.3 ZEND_CHECK_STACK_LIMIT @Yurunsoft
- Fixed no Content-Range response header when the range request returns all the contents of the file @Yurunsoft
- Optimized HTTP server performance @NathanFreeman
- Fixed truncated cookie @stnguyen90
- Fixed native-curl crash on PHP 8.3 @NathanFreeman
- Added CLOSE_SERVICE_RESTART, CLOSE_TRY_AGAIN_LATER, CLOSE_BAD_GATEWAY as valid close reasons for websocket @cjavad
- Fixed invalid errno after Server::Manager::wait() @JacobBrownAustin
- Fixed HTTP2 Typo @leocavalcante
v5.1.1
🐛 Bug Fixed
- Fixed memory leak issue in
HTTP coroutine client
@NathanFreeman - Fixed the issue of can not hook
pdo_odbc
@NathanFreeman - Fixed the error in executing
socket_import_stream()
@Yurunsoft - Fixed the issue with
Context::parse_multipart_data()
unable to handle empty request body @NathanFreeman - Fixed the issue with
PostgreSQL coroutine client
where the parameters are not working @Yurunsoft - Fixed the bug where
curl
crashes during destruction @matyhtf - Fixed the compatibility issue between
Swoole 5.x
and the latest version ofxdebug
@NathanFreeman - Fixed the problem of
class not found
error caused by coroutine switching during the process ofclass autoloading
@Yurunsoft - Fixed the issue of not being able to compile
Swoole
onOpenBSD
@ChihHao-Su @twose
🐛 Bug 修复
- 修复
http协程客户端
内存泄漏问题 (@NathanFreeman) - 修复
pdo_odbc
无法协程化的问题 (@NathanFreeman) - 修复
socket_import_stream()
执行错误的问题 (@Yurunsoft) - 修复
Context::parse_multipart_data()
无法处理空请求体的问题 (@NathanFreeman) - 修复
PostgreSQL协程客户端
参数不起作用的问题 (@Yurunsoft) - 修复
curl
在析构时会崩溃的bug (@matyhtf) - 修复
Swoole5.x
与新版的xdebug
不兼容问题 (@NathanFreeman) - 修复类
自动加载
的过程中发生协程切换导致提示类不存在
的问题 (@Yurunsoft) - 修复无法在
OpenBSD
编译swoole
的问题 (@ChihHao-Su) (@twose)
v5.1.0
✨ New Features
- Support
pdo_pgsql
coroutine hook (@matyhtf) - Support
pdo_odbc
coroutine hook (@matyhtf) - Support
pdo_oci
coroutine hook (@NathanFreeman) - Support
pdo_sqlite
coroutine hook (@NathanFreeman) - Add configuration for PDO connection pools for
pdo_pgsql
,pdo_odbc
,pdo_oci
,pdo_sqlite
(@NathanFreeman)
💪 Performance Improvement
- Improved performance of
Http\Server
, can increase up to60%
in extreme cases (@matyhtf) (@NathanFreeman)
🐛 Bug Fixed
- Fixed the memory leak caused by each request of the
WebSocket coroutine client
(@matyhtf) (@NathanFreeman) - Fixed the issue where graceful shutdown of the
HTTP coroutine server
was not causing the client to exit (@matyhtf) - Fixed the issue where adding the
--enable-thread-context
option during compilation was causingProcess::signal()
to not work (@NathanFreeman) - Fixed the issue where the connection count was being calculated incorrectly when a process exited abnormally in
SWOOLE_BASE
mode (@Yunrunsoft) - Fixed the incorrect signature of the
stream_select()
function (@Yunrunsoft) (@NathanFreeman) - Fixed the case sensitivity issue with the MIME information in files (@hongweipeng)
- Fixed the spelling mistake in
Http2\Request::$usePipelineRead
, which was causing a warning to be thrown in PHP 8.2 environment (@NathanFreeman) - Fixed the memory leak issue in
SWOOLE_BASE
mode (@dongzitai) (@NathanFreeman) - Fixed the memory leak issue caused by setting the expiration time of a cookie in
Http\Response::cookie()
(@NathanFreeman) - Fixed the connection leak issue in
SWOOLE_BASE
mode (@NathanFreeman)
🔑 Kernel
- Fixed the function signature issue of php_url_encode in Swoole under PHP 8.3 (@YepYuYu)
- Fixed the issue with unit testing options (@YepYuYu)
- Optimized and refactored the code (@matyhtf)
- Fix compatibility with PHP 8.3 (@Yunrunsoft) (@matyhtf)
- Unsupported compilation on 32-bit operating systems
🌕🥮🥰 Happy Mid-Autumn Festival!
✨ 新特性
- 增加对
pdo_pgsql
的协程化支持 (@matyhtf) - 增加对
pdo_odbc
的协程化支持 (@matyhtf) - 增加对
pdo_oci
的协程化支持 (@NathanFreeman) - 增加对
pdo_sqlite
的协程化支持 (@NathanFreeman) - 增加
pdo_pgsql
,pdo_odbc
,pdo_oci
,pdo_sqlite
的连接池配置。(@NathanFreeman)
💪 性能提高
- 改进了
Http\Server
的性能,极限情况下可以提升60%
(@matyhtf) (@NathanFreeman)
🐛 Bug 修复
- 修复
WebSocket协程客户端
每次请求造成的内存泄漏 (@matyhtf) (@NathanFreeman) - 修复
http协程服务端
优雅退出导致客户端不退出的问题 (@matyhtf) - 修复编译的时候加入了
--enable-thread-context
选项会导致Process::signal()
不起作用(@NathanFreeman) - 修复
在SWOOLE_BASE模式
下,当进程非正常退出时,连接数统计错误的问题 (@Yunrunsoft) - 修复
stream_select()
函数签名错误 (@Yunrunsoft) (@NathanFreeman) - 修复文件MIME信息大小写敏感错误 (@hongweipeng)
- 修复
Http2\Request::$usePipelineRead
拼写错误导致在PHP8.2的环境下会抛出警告。 (@NathanFreeman) - 修复在
SWOOLE_BASE
模式下的内存泄漏问题 (@dongzitai) (@NathanFreeman) - 修复当
Http\Response::cookie()
设置cookie
的过期时间导致的内存泄漏问题 (@NathanFreeman) - 修复在
SWOOLE_BASE
模式下的连接泄漏问题 (@NathanFreeman)
🔑 内核
- 修复swoole在php8.3下的php_url_encode的函数签名问题 (@YepYuYu)
- 修复单元测试选项问题 (@YepYuYu)
- 优化,重构代码 (@matyhtf)
- 兼容PHP8.3 (@Yunrunsoft) (@matyhtf)
- 不支持32位操作系统上编译