Home arrow PHP arrow Page 7 - Logging With PHP

Artificial Intelligence - PHP

Want to log script activity in your Web application, but haveno clue where to begin? Take our handy tour of PHP's logging functions,and find out how simple it really is.

TABLE OF CONTENTS:
  1. Logging With PHP
  2. The Bare Necessities
  3. Turning The Tables
  4. Turning Up The Heat
  5. Biting Into A PEAR
  6. Destination Unknown
  7. Artificial Intelligence
  8. Big Brother Is Watching
  9. Closing Time
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 53
November 27, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
You can also configure PHP to automatically log all script errors to a specific file via the special "log_errors" configuration directive in "php.ini". This directive, when set to true, logs all PHP errors to either a user-specified log file (the value of this file must be specified in the "error_log" configuration directive, also set via "php.ini"), or to the Web server error log if no log file is specified.

Consider the following example, which demonstrates:

<?php // turn on automatic error logging ini_set('log_errors', true); // include non-existent file include("non.existent.file.php"); ?>
In this case, I'm manually instantiating an error by attempting to include a file which does not exist. Obviously, PHP will barf and display an error screen containing the following:

Warning: Failed opening 'non.existent.file.php' for inclusion (include_path='.;/usr/local/php/includes') in error.php on line 10
The same error also appears in the server's error log:

[Tue Nov 26 12:49:31 2002] [error] PHP Warning: Failed opening 'non.existent.file.php' for inclusion (include_path='.;/usr/local/php/includes') in error.php on line 10
You can turn off PHP error display, and only have the error message appear in the log file, by setting the "display_errors" variable (also accessible via "php.ini") to false. Consider the following variant of the previous example, which demonstrates:

<?php // turn on automatic error logging ini_set('log_errors', true); // turn off error display ini_set('display_errors', false); // include non-existent file include("non.existent.file.php"); ?>
In this case, though an error takes place, it is never displayed to the user, but merely gets logged to the server's error log.

On *NIX systems, setting the "error_log" variable to the special value "syslog" logs all errors via the standard "syslog" daemon.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: