HomePHP Page 6 - Error and Exception Handling in PHP
Sending a Message to the Logging Destination - PHP
Mistakes are inevitable, in life, programming, and application submissions. You can prepare for errors by making sure your application is designed to respond to them. This two-part article explains how PHP handles errors. It is excerpted from chapter 8 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).
Thesyslog()function is responsible for sending a custom message to the syslog. Its prototype follows:
int syslog(int priority, string message)
The first parameter,priority, specifies the syslog priority level, presented in order of severity here:
LOG_EMERG: A serious system problem, likely signaling a crash
LOG_ALERT: A condition that must be immediately resolved to avert jeopardizing system integrity
LOG_CRIT: A critical error, which could render a service unusable but does not necessarily place the system in danger
LOG_ERR: A general error
LOG_WARNING: A general warning
LOG_NOTICE: A normal but notable condition
LOG_INFO: A general informational message
LOG_DEBUG: Information that is typically only relevant when debugging an application
The second parameter,message, specifies the text of the message that you’d like to log. If you’d like to log the error message as provided by the PHP engine, you can include the string%min the message. This string will be replaced by the error message string (strerror) as offered by the engine at execution time.
Now that you’ve been acquainted with the relevant functions, here’s an example: