-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement GH-12385: flush headers without body when calling flush() #12785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
GH-12385 (flush with fastcgi does not force headers to be sent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The feature request is about sending headers when
Am I understanding you right, headers are always sent with related discussion https://serverfault.com/questions/488767/how-do-i-enable-php-s-flush-with-nginxphp-fpm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It means that an FCGI packet is sent for the header and body to the web server; whereas previously it would only send one. This implements the behaviour you want.
No. FPM will send it to the web server separately, but it all depends on what your web server does with it then, this is outside of the hands of PHP. The discussion link indeed summarizes it well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah nginx buffers responses by default. You would need to disable buffering ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on https://stackoverflow.com/questions/20018803/flush-output-buffer-in-apache-nginx-setup#23171223 and https://stackoverflow.com/questions/4870697/php-flush-that-works-even-in-nginx it seems a header from php can be sent to inform the nginx to not cache the response. FYI only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
GH-12385 (flush with fastcgi does not force headers to be sent)
FPM: GH-12385 - flush with fastcgi does not force headers to be sent
that's the format that I use for other FPM tests (mostly) |
||
--SKIPIF-- | ||
<?php | ||
include "skipif.inc"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
require_once "tester.inc"; | ||
|
||
$cfg = <<<EOT | ||
[global] | ||
error_log = {{FILE:LOG}} | ||
[unconfined] | ||
listen = {{ADDR}} | ||
pm = static | ||
pm.max_children = 1 | ||
EOT; | ||
|
||
$code = <<<PHP | ||
<?php | ||
header("X-Test: 12345"); | ||
flush(); | ||
var_dump(headers_sent()); | ||
PHP; | ||
|
||
$tester = new FPM\Tester($cfg, $code); | ||
$tester->start(); | ||
$tester->expectLogStartNotices(); | ||
$response = $tester->request(); | ||
$response->expectHeader("X-Test", "12345"); | ||
$response->expectBody("bool(true)"); | ||
Comment on lines
+24
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
flush();
var_dump(headers_sent());
PHP;
$tester = new FPM\Tester($cfg, $code);
$tester->start();
$tester->expectLogStartNotices();
$response = $tester->request();
$response->expectHeader("X-Test", "12345");
$response->expectBody("bool(true)");
$headersSentBeforeFlush = headers_sent();
flush();
$headersSentAfterFlush = headers_sent();
var_dump($headersSentBeforeFlush);
var_dump($headersSentAfterFlush);
PHP;
$tester = new FPM\Tester($cfg, $code);
$tester->start();
$tester->expectLogStartNotices();
$response = $tester->request();
$response->expectHeader("X-Test", "12345");
$response->expectBody("bool(false)\nbool(true)");
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't this this is necessary. We don't need to test what's given which is that headers are not sent at the beginning of request. |
||
$tester->terminate(); | ||
$tester->expectLogTerminatingNotices(); | ||
$tester->close(); | ||
|
||
?> | ||
Done | ||
--EXPECT-- | ||
Done | ||
--CLEAN-- | ||
<?php | ||
require_once "tester.inc"; | ||
FPM\Tester::clean(); | ||
?> |