Skip to content

sapi/cli: support Expect 100-continue in PHP dev server - #23245

Open
Sjord wants to merge 4 commits into
php:masterfrom
Sjord:cli-server-expect-100-continue
Open

sapi/cli: support Expect 100-continue in PHP dev server#23245
Sjord wants to merge 4 commits into
php:masterfrom
Sjord:cli-server-expect-100-continue

Conversation

@Sjord

@Sjord Sjord commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

When posting large payloads, curl checks whether the server is ready for the body. It sends an Expect: 100-continue header and expects HTTP/1.1 100 Continue as the response before sending the body. The PHP development server did not support this, causing a timeout in curl. This made such requests take one second longer.

When posting large payloads, curl checks whether the server is ready for
the body. It sends an `Expect: 100-continue` header and expects
`HTTP/1.1 100 Continue` as the response before sending the body. The PHP
development server did not support this, causing a timeout in curl. This
made such requests take one second longer.

- https://everything.curl.dev/http/post/expect100.html
- php#23242
This is not a curl test, but a test of the behavior of the PHP
development server. It should thus not be in the curl directory but in
the sapi/cli directory.
@Sjord
Sjord force-pushed the cli-server-expect-100-continue branch from 1b0cb8d to 0052e12 Compare August 14, 2026 14:44
@Sjord
Sjord marked this pull request as ready for review August 14, 2026 15:17
@Sjord

Sjord commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@php/release-managers-86 @mbeccati Is this something you want in PHP 8.6?

@mbeccati

mbeccati commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@Sjord Seems like a useful fix to me. I will discuss with the team.

EDIT: we agree it's perfectly fine for 8.6

@Sjord

Sjord commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@iluuu1994 @Girgias Could you review this please?

@LamentXU123
LamentXU123 requested a review from devnexen August 20, 2026 13:20
@devnexen

Copy link
Copy Markdown
Member

ok will try my best to review, I have some questions ...

Comment thread sapi/cli/php_cli_server.c Outdated
append_http_status_line(&buffer, client->parser.http_major * 100 + client->parser.http_minor, 100, 0);
smart_str_appendl(&buffer, "\r\n", 2);
smart_str_0(&buffer);
php_cli_server_client_send_through(client, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the dev server meant to exit when the peer aborts here? If I m not mistaken, php_cli_server_client_send_through() call is reached from a place where a failed send() is fatal to the whole process, right ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reading the code I come to the same conclusion, but I cannot reproduce it. php_cli_server_client_send_through is also used in sapi_cli_server_send_headers, so I thought that this would be the appropriate function to use.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right right ... note that sapi_cli_server_send_headers is wrapped in zend_try (and is a sapi handler) ; this is where I would like Gina opinion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a bit further with this.

  • The test now sets the SO_LINGER option on the socket (if possible), which makes the send in php_cli_server_client_send_through fail. This indeed made the server exit.
  • In the calling code php_cli_server_client_send_through is now wrapped within zend_try to handle the error.

So this seems solved, but I am also a little bit out of my depth here so it would be nice to get another set of eyes on this.

Comment thread sapi/cli/tests/php_cli_server_expect_100_continue_curl.phpt
Sjord added 2 commits August 21, 2026 09:13
If php_cli_server_client_send_through fails while sending `HTTP/1.1 100
Continue` we don't want the server to exit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants