PHP: How to log fatal errors?

Hamidreza picture Hamidreza · Feb 17, 2012 · Viewed 12.5k times · Source

How i can log this error to a text file or database ?

Fatal error: Call to undefined method PROJECTS::ssss()

Answer

ThiefMaster picture ThiefMaster · Feb 17, 2012

It is not possible to handle fatal errors using a custom error handler.

The best solution is simply enabling error logging (e.g. to syslog) in your php.ini and then using a tool like logcheck/logsentry to receive regular emails about unusual syslog entries.
Instead of syslog PHP can also log errors to a file - simply have a look at the error logging options of php.ini.

log_errors = On
error_log = syslog
error_log = /path/to/some/folder/phperrors.log

Obviously you only want to use one of the error_log lines.