diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 156599f6f9d4d..695a693019821 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -355,11 +355,11 @@ static void sapi_fcgi_flush(void *server_context) { fcgi_request *request = (fcgi_request*) server_context; - if ( - !parent && - request && !fcgi_flush(request, 0)) { - - php_handle_aborted_connection(); + if (!parent && request) { + sapi_send_headers(); + if (!fcgi_flush(request, 0)) { + php_handle_aborted_connection(); + } } } diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index b3ae2f69cc556..12709ae063ab9 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -291,8 +291,11 @@ static void sapi_cgibin_flush(void *server_context) /* {{{ */ /* fpm has started, let use fcgi instead of stdout */ if (fpm_is_running) { fcgi_request *request = (fcgi_request*) server_context; - if (!parent && request && !fcgi_flush(request, 0)) { - php_handle_aborted_connection(); + if (!parent && request) { + sapi_send_headers(); + if (!fcgi_flush(request, 0)) { + php_handle_aborted_connection(); + } } return; } diff --git a/sapi/fpm/tests/gh12385.phpt b/sapi/fpm/tests/gh12385.phpt new file mode 100644 index 0000000000000..08b9882616679 --- /dev/null +++ b/sapi/fpm/tests/gh12385.phpt @@ -0,0 +1,46 @@ +--TEST-- +GH-12385 (flush with fastcgi does not force headers to be sent) +--SKIPIF-- + +--FILE-- +start(); +$tester->expectLogStartNotices(); +$response = $tester->request(); +$response->expectHeader("X-Test", "12345"); +$response->expectBody("bool(true)"); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +