php / php/php-src

fclose 500ms delay on a listening socket on Windows

オープン
#19,696 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Category: Streams OS: Windows Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず xp_socket.c と、レポートで言及されている php_sockop_close のパスから始め、Windows で stream_socket_server() がリスニングソケットを閉じる方法を追跡します。PHP 8.4.12 の Windows タイミング比較を再現し、適切なリグレッションケースがないか既存のソケットテストを調査します。完了の条件は、socket_close() の動作を変更せずに、報告されている 500ms の遅延なしでストリームサーバーが終了することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
networking
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。