Outputting all PHP errors to database not error_log

后端 未结 2 1691
天命终不由人
天命终不由人 2020-11-27 21:37

Is it possible to make all PHP errors be written to MySQL instead of to the standard error_log file. I guess this would be possible if i wrote my own error handler from scra

2条回答
  •  离开以前
    2020-11-27 21:57

    I don't think it can be done without building an own error handler, but technically, that is the one global change you're looking for.

    Modified example from the manual:

    function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
         // you'd have to import or set up the connection here 
         mysql_query("INSERT INTO error_log (number, string, file, line) ".
                     "VALUES .....");         
    
        /* Don't execute PHP internal error handler */
        return true;
    }
    

    then

    // set to the user defined error handler
    $old_error_handler = set_error_handler("myErrorHandler");
    

提交回复
热议问题