How to turn on all error and warnings and log them to a file but to set up all of that within the script (not changing anything in php.ini). I want to define a file name and so that all errors and warnings get logged into it.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Take a look at the
log_errors
configuration option in php.ini. It seems to do just what you want to. I think you can use theerror_log
option to set your own logging file too.When the
log_errors
directive is set toOn
, any errors reported by PHP would be logged to the server log or the file specified witherror_log
. You can set these options withini_set
too, if you need to.(Please note that
display_errors
should be disabled in php.ini if this option is enabled)See
error_log
— Send an error message somewhereExample
You can customize error handling with your own error handlers to call this function for you whenever an error or warning or whatever you need to log occurs. For additional information, please refer to the Chapter Error Handling in the PHP Manual
Use the following code:
Then watch the file:
Or update
php.ini
as described in this blog entry from 2008.In addition, you need the "AllowOverride Options" directive for this to work. (Apache 2.2.15)
add this code in .htaccess (as an alternative of php.ini / ini_set function):
p.s. this is for Apache-type servers.
That's my personal short function