php / php/php-src

fclose 500ms delay on a listening socket on Windows

Đang mở
#19,696 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Category: Streams OS: Windows Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với xp_socket.c và đường dẫn php_sockop_close được đề cập trong báo cáo, sau đó truy vết cách stream_socket_server() đóng một socket đang lắng nghe trên Windows. Tái hiện phép so sánh thời gian trên Windows với PHP 8.4.12 và kiểm tra các bài kiểm thử socket hiện có để tìm một trường hợp hồi quy phù hợp. Được xem là hoàn tất khi máy chủ stream đóng mà không có độ trễ 500ms được báo cáo, trong khi hành vi của socket_close() vẫn không thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
networking
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.