Logging PHP Errors

In the previous example, errors were handled by simply printing them out in detail or not. Another option is to log the errors: make a permanent note of them somehow. For this purpose, the error_log() function instructs PHP how to file an error.

error_log (message, type, destination,
→ extra headers);

The message value should be the text of the logged error. The type dictates how the error is logged. Table 6.2 lists the types of error logging you can use. The destination parameter can be either the name of a file (for log type 3) or an email address (for log type 1). The extra headers argument is used only when sending emails (log type 1). Both the destination and extra headers are optional.

Table 6.2. PHP can log errors ...

Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.