fclose 500ms delay on a listening socket on Windows
未关闭
还没有人认领这个 Issue。
Bug
Category: Streams
OS: Windows
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
echo "Stream test\n";
for ($i = 0; $i < 10; $i++) {
$s = stream_socket_server("tcp://127.0.0.1:0/", $errno, $errstr);
$start = microtime(1);
fclose($s);
echo sprintf("Closed in %.3f\n", microtime(1) - $start);
}
echo "Socket test\n";
for ($i = 0; $i < 10; $i++) {
$s = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($s, "127.0.0.1", 0);
socket_listen($s);
$start = microtime(1);
socket_close($s);
echo sprintf("Closed in %.3f\n", microtime(1) - $start);
}
?>
Resulted in this output:
Stream test
Closed in 0.504
Closed in 0.508
Closed in 0.510
Closed in 0.508
Closed in 0.514
Closed in 0.510
Closed in 0.510
Closed in 0.509
Closed in 0.511
Closed in 0.508
Socket test
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
But I expected this output instead:
Stream test
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Socket test
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
Closed in 0.000
The problem dates back since at least PHP 5.4.0 as described [here]. I answered there but just tested with the most recent PHP for the Windows platform and confirmed it.
In short - I think that xp_socket.c/php_sockop_close should not poll a listening socket before closing it.
PHP Version
PHP 8.4.12 (cli) (built: Aug 26 2025 18:04:08) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.12, Copyright (c) Zend Technologies
Operating System
Windows 10 Pro x64
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 xp_socket.c 和报告中提到的 php_sockop_close 路径开始,然后跟踪 stream_socket_server() 在 Windows 上关闭监听 socket 的过程。重现 PHP 8.4.12 的 Windows 计时比较,并检查现有的 socket 测试以寻找合适的回归用例。完成的标准是 stream server 在没有报告中的 500ms 延迟的情况下关闭,同时 socket_close() 的行为保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100