Skip to content

Commit a1facc9

Browse files
committed
Implement phpGH-12385: flush headers without body when calling flush()
1 parent 1e7c64b commit a1facc9

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

Diff for: sapi/cgi/cgi_main.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ static void sapi_fcgi_flush(void *server_context)
355355
{
356356
fcgi_request *request = (fcgi_request*) server_context;
357357

358-
if (
359-
!parent &&
360-
request && !fcgi_flush(request, 0)) {
361-
362-
php_handle_aborted_connection();
358+
if (!parent && request) {
359+
sapi_send_headers();
360+
if (!fcgi_flush(request, 0)) {
361+
php_handle_aborted_connection();
362+
}
363363
}
364364
}
365365

Diff for: sapi/fpm/fpm/fpm_main.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ static void sapi_cgibin_flush(void *server_context) /* {{{ */
291291
/* fpm has started, let use fcgi instead of stdout */
292292
if (fpm_is_running) {
293293
fcgi_request *request = (fcgi_request*) server_context;
294-
if (!parent && request && !fcgi_flush(request, 0)) {
295-
php_handle_aborted_connection();
294+
if (!parent && request) {
295+
sapi_send_headers();
296+
if (!fcgi_flush(request, 0)) {
297+
php_handle_aborted_connection();
298+
}
296299
}
297300
return;
298301
}

Diff for: sapi/fpm/tests/gh12385.phpt

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
GH-12385 (flush with fastcgi does not force headers to be sent)
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
10+
require_once "tester.inc";
11+
12+
$cfg = <<<EOT
13+
[global]
14+
error_log = {{FILE:LOG}}
15+
[unconfined]
16+
listen = {{ADDR}}
17+
pm = static
18+
pm.max_children = 1
19+
EOT;
20+
21+
$code = <<<PHP
22+
<?php
23+
header("X-Test: 12345");
24+
flush();
25+
var_dump(headers_sent());
26+
PHP;
27+
28+
$tester = new FPM\Tester($cfg, $code);
29+
$tester->start();
30+
$tester->expectLogStartNotices();
31+
$response = $tester->request();
32+
$response->expectHeader("X-Test", "12345");
33+
$response->expectBody("bool(true)");
34+
$tester->terminate();
35+
$tester->expectLogTerminatingNotices();
36+
$tester->close();
37+
38+
?>
39+
Done
40+
--EXPECT--
41+
Done
42+
--CLEAN--
43+
<?php
44+
require_once "tester.inc";
45+
FPM\Tester::clean();
46+
?>

0 commit comments

Comments
 (0)