-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
初步设想,最终版本可能会有所调整。
1. 增加 Co::setTimeLimit() 函数
function Co::setTimeLimit(double $timeout);为协程设置一个最大运行时间,超时后会触发 Swoole\Coroutine\TimeoutExeception 异常。
function onRequest($req, $resp) {
try {
// 设置当前协程最大执行时间为 2 秒
Co::setTimeLimit(2.0);
// 执行业务逻辑 ...
$resp->status(200);
$resp->end($output);
} catch(Swoole\Coroutine\TimeoutExeception $e) {
$resp->status(504);
$resp->end("REQUEST TIMEOUT");
} catch(Swoole\Coroutine\CanceledExeception $e) {
}2. 增加新的协程客户端
ext-pdo_firebirdext-ftpext-ssh2system()passthru()
3. 增强 PHP Stream 异步支持,允许独立使用
允许在关闭 Stream HOOK 后,使用 async. 前缀单独开启异步PHP Stream支持。
// 关闭 Runtime Hook
Swoole\Runtime::setHookFlags(0);
$file = fopen("async.file:///data/your_file.log", "a+");
// tcp
$tcp = stream_socket_client("async.tcp://127.0.0.1:9501"); // IPv4
$tcp = stream_socket_client("async.tcp://[::1]:9501"); // IPv6
// udp
$tcp = stream_socket_client("async.udp://127.0.0.1:9502");
// ssl
$ssl = stream_socket_client("async.ssl://127.0.0.1:9501");
// unix
$ssl = stream_socket_client("async.udg:///var/run/docker.sock"); // unix dgram
$ssl = stream_socket_client("async.unix:///var/run/docker.sock"); // unix stream与 Runtime Hook 不同,async. 协议的 stream 总是可用的。
4. 支持 PHP 8.5,废弃 PHP 8.1
根据 https://www.php.net/supported-versions.php ,8.1 版本将在 31 Dec 2025 终止维护,进入End of Life 阶段。因此 swoole 也将不再支持此版本。
5. 绑定检测打印堆栈
Socket 绑定检测的 fatal error 打印协程堆栈
- 读写操作
socket失败的协程堆栈 - 当前占有
socket的协程堆栈
6. 废弃所有同步阻塞特性的支持
在 6.2版本之后,将不再包含任何同步 IO 的支持
Swoole\Clientswoole_client_select()Server::taskWaitMulti()同步模式Server MsgQueue支持Swoole\Process同步模式
7. SAPI 调整,仅支持 Cli
移除其他SAPI的支持,仅限于cli、phpdbg 命令行模式
8. 新增 URL Rewrite 模块
仅用于静态文件处理器,可改写文件路径。示例:
$http->set([
'document_root' => __DIR__,
'enable_static_handler' => true,
'static_handler_locations' => ['/static'],
'url_rewrite_rules' => [
'~^/view/post/(\d+)$~' => '/static/$1.html',
'/article/' => '/static/article/'
]
]);支持正则匹配和字符串匹配两种方式:
- 正则:必须以
~作为开头和结尾 - 字符串
作用是将匹配到的 URL 替换为实际的 URL 并转发给静态处理器。
jingjingxyk
Metadata
Metadata
Assignees
Labels
No labels