-
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.
Suggested change
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
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(); | ||||||||||||||||||||||||||||||||||||||||||||||||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature request is about sending headers when
flush()
is called. I am not sure exactly what you meant by the cited sentence, but if the response buffer/body is empty, no (empty) packet for data should be sent.Am I understanding you right, headers are always sent with
flush()
(even with empty body) but small body is not sent even ifflush()
is called?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 comment
The 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.
Basically if you only send little data (be it headers or body content, doesn't matter) to nginx then it will wait for more data in the default configuration before sending data to the browser. That's what I wanted to highlight: that the usability highly depends of the behaviour of the web server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah nginx buffers responses by default. You would need to disable buffering (
fastcgi_buffering off
) to potentially see impact of this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.