From 4c654511fed00ffa9955559bee64b92a48d46f07 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sat, 1 Aug 2026 00:18:28 +0800 Subject: [PATCH] Fix GH-7781: Avoid HTML in CLI server startup warnings --- NEWS | 4 ++++ sapi/cli/php_cli_server.c | 9 ++++++++- sapi/cli/tests/gh7781.phpt | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 sapi/cli/tests/gh7781.phpt diff --git a/NEWS b/NEWS index 4364d69650e5..07caabace848 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.6.0beta1 +- CLI: + . Fixed bug GH-7781 (Built-in web server prints HTML in startup warnings). + (Matthias Görgens) + - GMP: . Added optional $definitely_prime output parameter to gmp_prevprime(). (Weilin Du) diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 85028cc03f7c..db72aafda988 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -2797,6 +2797,8 @@ int do_cli_server(int argc, char **argv) /* {{{ */ char *php_optarg = NULL; int php_optind = 1; int c, r; + bool html_errors; + zend_result server_ctor_result; const char *server_bind_address = NULL; extern const opt_struct OPTIONS[]; const char *document_root = NULL; @@ -2868,7 +2870,12 @@ int do_cli_server(int argc, char **argv) /* {{{ */ router = argv[php_optind]; } - if (FAILURE == php_cli_server_ctor(&server, server_bind_address, document_root, router)) { + /* Startup diagnostics are written to a terminal, not an HTTP response. */ + html_errors = PG(html_errors); + PG(html_errors) = false; + server_ctor_result = php_cli_server_ctor(&server, server_bind_address, document_root, router); + PG(html_errors) = html_errors; + if (FAILURE == server_ctor_result) { return 1; } sapi_module.phpinfo_as_text = 0; diff --git a/sapi/cli/tests/gh7781.phpt b/sapi/cli/tests/gh7781.phpt new file mode 100644 index 000000000000..e0c4f647d149 --- /dev/null +++ b/sapi/cli/tests/gh7781.phpt @@ -0,0 +1,31 @@ +--TEST-- +GH-7781 (Built-in server startup warnings should not contain HTML) +--FILE-- + +--EXPECT-- +int(1) +bool(false) +bool(true) +bool(true)