[Debug] Check headers sent before sending PHP response

If the response contents has been sent before an error occurs, PHP
triggers the warning "Cannot modify header information - headers already sent"

This change ensure that the error message is echoed, while it's impossible
to change the HTTP status code and headers.