When you write to the syslog, the error messages look like this:
Dec 5 10:56:37 example.com httpd: PHP Warning:
fopen(/home/www/htdocs/subscribers.txt): failed to open stream: Permission
denied in /home/www/htdocs/book/8/displayerrors.php on line 3
218 CHAPTER 8 ?– ERRO R AND EXCEPTION HANDL ING
When you write to a separate text file, the error messages look like this:
[05-Dec-2005 10:53:47] PHP Warning:
fopen(/home/www/htdocs/subscribers.txt): failed to open stream: Permission
denied in /home/www/htdocs/book/8/displayerrors.php on line 3
As to which one to use, that is a decision that you should make on a per-environment
basis. If your Web site is running on a shared server, using a separate text file or database
table is probably your only solution. If you control the server, using the syslog
may be ideal because you??™d be able to take advantage of a syslog-parsing utility to
review and analyze the logs. Take care to examine both routes and choose the strategy
that best fits the configuration of your server environment.
PHP enables you to send custom messages as well as general error output to the
system syslog. Four functions facilitate this feature. These functions are introduced
in this section, followed by a concluding example.
Initializing PHP??™s Logging Facility
The define_syslog_variables() function initializes the constants necessary for using
the openlog(), closelog(), and syslog() functions.
Pages:
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296