Handling the error_handler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nigel A. Chapman

    Handling the error_handler

    I've recently been looking into PHP's custom error handler support,
    which seems to me to fail at exactly the point that you need it to start
    working. I quote:

    "Note: The following error types cannot be handled with a user defined
    function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING,
    E_COMPILE_ERROR and E_COMPILE_WARNI NG."

    -- from http://au.php.net/manual/en/function...or-handler.php

    How do I get PHP to email me when a *genuinely serious* error occurs?
    Those, after all, are the ones that I really want to be told about. Is
    there the PHP equivalent of an 'onAbort' hook anywhere?

    Basically, I want to know what's gone wrong when it happens, rather than
    needing to look through logfiles to see what went wrong in the past.

    How do people normally do this?

    Nigel Chapman,
    Sydney Australia.

    kale77in at hotmail * (don't reply to my [From:] address, it's bogus)

  • Chris Morris

    #2
    Re: Handling the error_handler

    "Nigel A. Chapman" <nchapman@bigpo nd.com> writes:[color=blue]
    > How do I get PHP to email me when a *genuinely serious* error occurs?
    > Those, after all, are the ones that I really want to be told about.
    > Is there the PHP equivalent of an 'onAbort' hook anywhere?
    >
    > Basically, I want to know what's gone wrong when it happens, rather
    > than needing to look through logfiles to see what went wrong in the
    > past.
    >
    > How do people normally do this?[/color]

    I have PHP set up to send its error messages through syslog to
    /var/log/user.log

    Then, I run the logcheck program hourly from cron, and get the
    error messages emailed to me if any happened since the last run.

    If you really needed almost instant notification, you could run
    logcheck every five minutes - it's fairly lightweight.

    Logcheck lets you set up a lot of good filtering so you only get
    interesting stuff. I'd recommend using it in combination with a good
    syslog program such as syslog-ng to make filtering easier.

    --
    Chris

    Comment

    • Nigel A. Chapman

      #3
      Re: Handling the error_handler

      Thanks, that's helpful. I'll fall back to that position unless I can
      find something that doesn't require access to the server.

      Chris Morris wrote:
      [color=blue]
      > I have PHP set up to send its error messages through syslog to
      > /var/log/user.log
      >
      > Then, I run the logcheck program hourly from cron, and get the
      > error messages emailed to me if any happened since the last run.
      >
      > If you really needed almost instant notification, you could run
      > logcheck every five minutes - it's fairly lightweight.
      >
      > Logcheck lets you set up a lot of good filtering so you only get
      > interesting stuff. I'd recommend using it in combination with a good
      > syslog program such as syslog-ng to make filtering easier.[/color]

      Comment

      • Nigel A. Chapman

        #4
        Re: Handling the error_handler

        Tony Marston wrote:
        [color=blue][color=green]
        >>"Note: The following error types cannot be handled with a user defined
        >>function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING,
        >>E_COMPILE_ERR OR and E_COMPILE_WARNI NG."[/color][/color]
        [color=blue]
        > Take a look at http://www.tonymarston.net/php-mysql/errorhandler.html
        > which shows you how to create an error handler which will send an
        > email if a fatal error is encountered.[/color]

        I'll give it a run, but I don't see from your code how your
        user-defined-error function gets around the above-mentioned limitation
        in PHP. Does it really respond to parsing errors?

        --

        Nigel Chapman,
        Sydney Australia.

        kale77in at hotmail * (don't reply to my [From:] address, it's bogus)

        Comment

        • Tony Marston

          #5
          Re: Handling the error_handler

          "Nigel A. Chapman" <nchapman@bigpo nd.com> wrote in message news:<p87Ua.139 44$OM3.8867@new s-server.bigpond. net.au>...[color=blue]
          > Tony Marston wrote:
          >[color=green][color=darkred]
          > >>"Note: The following error types cannot be handled with a user defined
          > >>function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING,
          > >>E_COMPILE_ERR OR and E_COMPILE_WARNI NG."[/color][/color]
          >[color=green]
          > > Take a look at http://www.tonymarston.net/php-mysql/errorhandler.html
          > > which shows you how to create an error handler which will send an
          > > email if a fatal error is encountered.[/color]
          >
          > I'll give it a run, but I don't see from your code how your
          > user-defined-error function gets around the above-mentioned limitation
          > in PHP. Does it really respond to parsing errors?[/color]

          No. If a parsing error occurs then your script won't even run (this
          will be detected when you test your script). My error handler will
          trap runtime errors.

          Try using it, and force a few runtime errors just to see what happens.

          Tony Marston
          This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

          Comment

          Working...