Fix #60471: Solution for "Invalid request (Unexpected EOF)" message in built-in web server #2442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Possible solution to bug #60471.
The built-in web server generates a lot of confusing
Invalid request (Unexpected EOF)
error messages when using a browser that supports preconnect like Firefox or Chrome.In addition, Chrome uses a predictive TCP preconnect technique to speed up the request time. This means that for nearly every connection to a web server, Chrome will open more than one TCP connection as you can see here.
In this case, the first connection (
50685
) was used for the actual request while the other one (50686
) waits for a request for some other resource (like a favicon or whatever). You can see it hanging open when looking at the TCP connections withnettop
(on Mac).After a timeout (usually about 10 seconds) the
Invalid request (Unexpected EOF)
message is output from the PHP CLI web server. This error message is confusing to developers everywhere. So developers think they did something wrong and spend a lot of time looking for answers only to be greeted with lots of misinformation like "just add a favicon".Since preconnecting is starting to become a common practice with modern web browsers, this PR offers a possible solution by changing the behavior of the built-in web server in the following ways:
PHP_DEBUG
instead ofDEBUG
so we see them when using the--enable-debug
flag. (I don't know whereDEBUG
came from).Invalid request (Unexpected EOF)
message toClosed without sending a request; it was probably just a preconnect
so that a quick Google search for "preconnect" will explain all the things.The new output for closed TCP preconnections in debug mode would look like this.
Phew. I hope this clarifies things for everyone who has been pulling their hair out with this! :)