Home > Software design >  How can I display PHP error_reporting to the web-console?
How can I display PHP error_reporting to the web-console?

Time:03-18

So first off - I've been using this...

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

...for years and it works great!

Please note that as I say "errors", I mean any messages produced by the above script.

The problem I run in to is that as I'm working on the CSS/JS portions, these error messages can get hidden or overlap parts of the site, and make it difficult to read. I've been looking online, and while there is a plethora of information regarding error reporting (mostly repeating the information above), I am unable to find a way to separate out the errors from the page like you can in JS.

Is there a way that the above script (or an alternate one) can be modified to display errors in the web-console OR in a specific DIV that could be created (like a psudo-in-body-console sort of thing)?

CodePudding user response:

Better (and required for production environments anyway, for security) is to log the errors to a file on the server. PHP already allows you to configure it to do that. https://stackify.com/php-error-logs-guide is one of many tutorials available which explains how to set it up.

You can't make the errors appear in the web console or otherwise redirect them to a place on the page (unless you pepper your code with try/catch and then lots of custom code to collect the messages and echo them elsewhere, which is not something I'm going to suggest). If they're not caught, the errors appear as they occur, in whatever output position they occur in. You can't control that unfortunately (other than by sending them to a file instead).

You can always use your browser's View Source feature to see if there are hidden errors, but I agree it's not ideal. A log file would actually be a neater place to find them all.

Also you can tail the log file in another window so it'll continuously update whenever an error occurs, if that makes it easier to work with.

  • Related