Skip to content
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

Prepare AMP response at shutdown instead of output buffer callback #931

Merged
merged 2 commits into from
Feb 5, 2018

Conversation

westonruter
Copy link
Member

This will make it easier to debug things since printing can be done in shutdown function but cannot in output buffer callback.

Furthermore, this prevents a fatal error if print_r() is attempted in the output buffer callback:

PHP Fatal error: print_r(): Cannot use output buffering in output buffering display handlers in .../wp-content/plugins/amp/includes/class-amp-theme-support.php on line 863

@westonruter westonruter added this to the v0.7 milestone Feb 5, 2018
* @see AMP_Theme_Support::start_output_buffering()
*/
public static function finish_output_buffering() {
$output = ob_get_clean();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advise to avoid storing the output in a variable unless necessary, especially in the context of the output buffer. For instance the memory goes from 3018376 to 3006088 on my local install by moving ob_get_clean() to self::prepare_response( ob_get_clean() );.

@ThierryA ThierryA merged commit c293486 into develop Feb 5, 2018
@westonruter westonruter deleted the improve/output-buffering branch February 7, 2018 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants