Skip to content

Fix accepting secure connections on PHP 8 - #37

Merged
GrahamCampbell merged 2 commits into
1.9from
fix-tls-accept
Nov 25, 2026
Merged

GrahamCampbell merged 2 commits into
1.9from
fix-tls-accept

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Accepting a connection on a secure server socket has thrown a TypeError on PHP 8 since the first release, because the accepted stream is handed to socket_import_stream() in order to disable Nagle's algorithm, and that function cannot represent a TLS stream, so it returns false and socket_set_option() rejects it. The error is not an Exception, so nothing catches it and the server process dies on its first wss:// client. This sets the tcp_nodelay stream context option on the listening socket instead, which PHP applies to every accepted connection whether it is encrypted or not, and removes the call that needed the imported socket.

Importing the stream also switched off PHP's read buffer as a side effect, which is what kept each read from an accepted connection to the length asked for, and so kept the number of data events the rate limiter counts proportional to the bytes received. The accepted stream is therefore now made unbuffered explicitly. The new tests accept a plain connection and check that both of these took effect, and accept a TLS connection made from a second process.

@GrahamCampbell
GrahamCampbell marked this pull request as ready for review November 25, 2026 23:34
@GrahamCampbell
GrahamCampbell merged commit 43499f9 into 1.9 Nov 25, 2026
20 checks passed
@GrahamCampbell
GrahamCampbell deleted the fix-tls-accept branch November 25, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant