Skip to content

Turn off display_errors during the post-processing phase (sanitization) #1915

@westonruter

Description

@westonruter

A user reported a two fatal errors showing up in the log:

[28-Feb-2019 17:51:38 UTC] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 72 bytes) in .../wp-content/plugins/amp/vendor/sabberworm/php-css-parser/lib/Sabberworm/CSS/Parser.php on line 784
[28-Feb-2019 17:51:38 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

The second error is a symptom of the first (for that see #1914). The site has display_errors turned on and so the printing of the first error is causing the second error. To prevent the second error from happening, we need to turn off display_errors during post-processing.

This actually identifies an improvement to be made in the plugin: we need to turn off display_errors during post-processing so that this doesn't happen. This should be done in the AMP_Theme_Support::prepare_response() method:

public static function prepare_response( $response, $args = array() ) {
global $content_width;
$prepare_response_start = microtime( true );
if ( isset( $args['validation_error_callback'] ) ) {
_doing_it_wrong( __METHOD__, 'Do not supply validation_error_callback arg.', '1.0' );
unset( $args['validation_error_callback'] );
}
/*
* Check if the response starts with HTML markup.
* Without this check, JSON responses will be erroneously corrupted,
* being wrapped in HTML documents.
*/
if ( '<' !== substr( ltrim( $response ), 0, 1 ) ) {
return $response;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions