WordPress PHP error handling and reporting in production environment

I’m trying to find a solution on how to handle the displaying and logging of errors in a PHP (WordPress) production environment.

Is it possible to do the following (alternative suggestions welcome):

Read More
  • Capture critical errors and send immediate email notification (this looks like a promising solution, but haven’t tested in my production env yet).
  • Don’t display PHP errors on screen to visitors. Instead display a custom built error page. Something that’s friendlier than the PHP “white screen of death”. This includes the WordPress specific errors, like the “Error establishing a database connection” one.

Production environment details specific to this question:

  • WordPress 3.5.1
  • Web Host: Windows Azure Cloud
  • Web Server: IIS 7.5

What I’ve already configured:

  • Development (local), Staging and Production enviroments
  • Code is managed in source control (Team Foundation Server Version Control)
  • Tested builds are pushed to production (Windows Azure Cloud)
  • I have configured wp-config for multiple environments:

    • Development and Production connect to different databases.
    • Development configs:

      • WP_DEBUG = true
      • WP_DEBUG_DISPLAY = true
      • WP_DEBUG_LOG = true
      • display_errors (via @ini_set) = true
    • Production configs:

      • WP_DEBUG = false
      • WP_DEBUG_DISPLAY = false
      • WP_DEBUG_LOG = true
      • display_errors (via @ini_set) = false

Related posts

Leave a Reply

1 comment

  1. It’s best to just log errors to the server and then use bash or a server script that supports email and error analysis (instead of PHP). There are lots of log file tools out there, simple ones like Logwatch, Swatch, Octopussy, or more complex ones like Nagios.

    For errors which are triggered using WP_Error you can write an email alert or log function right into the class, that is if it’s your code.

    I recommend checking this out: https://github.com/pippinsplugins/WP-Logging

    Additionally WP supports a maintenance.php and a db-error.php file that you can customize, the last one being more beneficial to your question since it will handle WP related DB errors.

    You can of course use PHP to mail errors for example using the above: http://yoast.com/custom-wordpress-database-error-pages/

    But your really better off using log files and a log analyzer to do this type of work on a production server.