I cannot figure out how to report fatal errors. Today, I happened to notice a certain page that tried to access a class that wasn't defined, and the error was printed to the screen. Yikes!!

If a fatal error were to occur I want my site to to immediately send me a notification email and also to log the details on the server so I can give my site urgent attention. How can I handle fatal errors?

The only thing I've found out so far is that i can do a "error_reporting(0)", but that just prevents them from displaying. I need to intelligently handle fatal errors.

Help!
Jonathan

    sounds like an error_handler script
    PHP is not too bad in that matter!

    XXXIV. Error Handling and Logging Functions

    These are functions dealing with error handling and logging.
    They allow you to define your own error handling rules,
    as well as modify the way the errors can be logged.
    This allows you to change and enhance error reporting to suit your needs.

    With the logging functions, you can send messages directly to other machines,
    to an email
    (or email to pager gateway!), to system logs, etc.,
    so you can selectively log and monitor the most important parts of your applications and websites.

    The error reporting functions allow you to customize what level and kind of error feedback is given, ranging from simple notices to customized functions returned during errors.

    http://php.net/manual/en/ref.errorfunc.php

    Regards 🙂

      I'm not sure if there is anyway to "handle" a "fatal" error. . . by definition. If the script stops execution, how do you "handle" anything?

      Any word from a Real Guru(TM)? [edit]Hmm, perhaps I need to read up on the newer try/exception stuff ....[/edit]

      My motto is found in one of our member's sigs --- "if it can't be fixed, slap it with a dirty hack". If the thing were really critical, then I'd have a cron job run a script that tails the webserver log every minute, looks for "fatal error", and emails me the output. Fairly trivial, but cronjobs that run every minute are most likely frowned upon by many independent server admins and most every hosting company....

        You can't handle a "fatal" directly in your code.

        What you can do it log it, and have some back-end process (monitoring?) which watches the log for the string that a fatal outputs - this can then be hooked into your alerting system which can alert an engineer.

        Mark

          Write a Reply...