-
Notifications
You must be signed in to change notification settings - Fork 165
Ensure the entire template is passed to the output buffer callback for Optimization Detective to process #1317
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b3ce59e
Try considering PHP_OUTPUT_HANDLER_FINAL in output buffer callback
westonruter 13e068d
Iterate on output buffer handling
westonruter 523fc7a
Update test-optimization.php
nextend 3235f3b
Merge pull request #1428 from nextend/update/ob-handling
westonruter 15ca2f0
Remove final ob_end_clean() and add ob_get_level() assertions
westonruter 78967f5
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter f218dc8
Allow output buffer to be cleaned but not flushed
westonruter 0b4f2cd
Allow output buffer to be removable
westonruter 2c6ec0c
Use bitwise XOR on the standard flags to remove the flushable flag
westonruter 35085e8
Ensure only HTML documents are processed by Optimization Detective
westonruter 364fa43
Remove assert() checks
westonruter 1b62c1a
Avoid sending Server-Timing header when buffer is being cleaned
westonruter 26e859d
Fix passing arg name to _doing_it_wrong()
westonruter 21ebb97
Improve escaping output by wrapping entire string in esc_html()
westonruter 8cbcbd6
Merge pull request #1443 from WordPress/fix/server-timing-after-ob-clean
85e9c2b
Merge pull request #1442 from WordPress/fix/od-processing-non-html-re…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Iterate on output buffer handling
- Loading branch information
commit 13e068d2673bad734dadf622a1fc3c1eb1d9736d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A few questions so that I understand this:
ob_clean()? Or for other things as well?$phaseand what's the purpose ofPHP_OUTPUT_HANDLER_FINALin this? Why are both checks needed?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.
That's a good point. There's also the consideration of
ob_flush(). Currently if this gets called then the resulting buffer passed into the filter is not complete. I've improved this in f218dc8 by making it so that the buffer is cleanable but not flushable.The
$phaseprovides information about why the handler was invoked. Note that bitwise operations are being used here (¬&&), so it is checking if the$phasecontains the final flag.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.
@westonruter Thanks, I had indeed missed the bitwise &, so this is only one check, makes sense.
Reading your code comments around the custom flag handling, I'm trying to understand: Does this mean that calling
ob_flush()anywhere while this output buffer is active will trigger an error? If so, I think we need to review whether/how that function is commonly used by plugins, mostly caching plugins of course. While it seems necessary for our functionality to be reliable, it also seems risky in terms of cross-plugin compatibility, like you're already indicating in your TODO.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 won't cause an error, no. It just results in
ob_flush()returning false, which is included in the unit tests.I'm addressing the TODO in another PR as it's not really related to output buffering.
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.
Ok, but what about breakage by flushing not being possible in a plugin where that might be intended? That's where I think we need to take a look at the ecosystem to see if that's a real or just a theoretical problem.
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.
That would be a situation where a plugin is attempting to flush the output buffer for a buffer it didn't open, which would be poor form. I did look over the instances of
ob_flush()in WPDirectory and I didn't see any obvious examples whereob_flush()was being used in frontend contexts without also having calledob_start(): so they'd only be flushing their own buffer. So I think we're fine here. We'll need to do more testing with actual sites to discover if there is a compatibility problem.