Created
June 27, 2013 09:33
-
-
Save rscata/5875202 to your computer and use it in GitHub Desktop.
error log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_log('A connection to the database could not be opened.', 1, '[email protected]'); //send error to email | |
error_log('A connection to the database could not be opened.', 3, '/var/log/php_errors.log'); //log into a file | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//shows an example of an error handler that writes logs into a file and rotates the logfile when it gets above 1 KB. | |
function log_roller($error, $errorString) | |
{ | |
$file = '/var/log/php_errors.log'; | |
if(filesize($file) > 1024) { | |
rename($file, $file . (string) time()); | |
clearstatcache(); | |
} | |
} | |
error_log($errorString, 3, $file); | |
set_error_handler('log_roller'); | |
for($i = 0; $i < 5000; $i++) { | |
trigger_error(time() . ": Just an error, ma'am.\n"); | |
} | |
restore_error_handler(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment