How can I stop the buffering of PHP output from error messages?

Well, now that I’ve gone a little deeper into it, I understand that this is a stupid question and a wrong one. It turns out that the author of the legacy code that I supported, welcomed the error log in another file using the instruction php_init. Hi-jacking occurred at the same time as output buffering, and it looked as if output buffering was dropping my error messages.

So, Mr. Moderator, feel free to delete this. Thanks to those who answered in good faith.


Given the following PHP script:

<?php 
error_log('test'); 

ob_start();

error_log('test2');

ob_end_flush();
?>

I get the following error log output:

[04-Feb-2010 11:30:38] test

Why does output buffering contain my error messages? How can I make him stop?

, , ?

( PHP 5.2.4-2ubuntu5.10)

+3
2

ob_start()

PHP script, , ob_start(), ob_end_flush()

echo 'before output buffer';
ob_start();
throw new Exception('this will be seen');
ob_end_flush();

Logger

, holder, ( error ), :

class Logger
{
    private $_messages = array();

    public function __construct()
    {
        $this->_messages['errors'] = array();
        $this->_messages['debug'] = array();
    }

    public function error($msg)
    {
        $this->_messages['errors'][] = $msg;
    }

    public function debug($msg)
    {
        $this->_messages['debug'] = $msg;
    }

    public function getErrors()
    {
        return $this->_messages['errors'];
    }

}

$logger = new Logger();

$logger->error('error1');

ob_start();

$logger->error('error2');

ob_end_flush();

print_r($logger->getErrors());

-, ,

+7

, :

error_log(),

  • , , ob_get_contents()
  • , ob_clean()
  • ob_flush() es
  • echo()
0

Source: https://habr.com/ru/post/1731428/


All Articles