Page 1 of 1

PHP error reports by localhost - How?

Posted: Sun Nov 11, 2007 3:29 pm
by Jonah Bron
My server give the errors in a php file when it is run, and the line, and the file location, etc. But, my localhost I have setup on my computer does not. Is this an add on that one must download from php.net? Any advice much appreciated. :smile:

Posted: Sun Nov 11, 2007 5:01 pm
by phpBuddy
Have a look in your php.ini
You can configure how error reports will be handled.
If you want to know where this file is, run phpinfo(), for example:
Loaded Configuration File C:\php\php.ini

There are 2 settings that effect error reports.
Both of them can can be changed in your scripts, as well in php.ini.

- display_errors = On/Off
- error_reporting = E_ALL (shows everything, including E_NOTICES)
- error_reporting = E_ALL &~ E_NOTICES (shows Errors and Warnings, but not notices.)


Read more in your php.ini file and here:
http://php.net/error_reporting

Posted: Sun Nov 11, 2007 7:25 pm
by Jonah Bron
Thanks for the reply. I did as you said, and un-commented display_errors, and set it to On, and un-commented error_reporting, and set it to E_ALL. It still doesn't work. Do you have to restart you computer to make it work? I did try restarting the Apache service, but that didn't work either. Thanks for your help so far :D

Posted: Sun Nov 11, 2007 8:02 pm
by Bogey
Here is what I have and it is showing errors for me...

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
display_errors = On
display_startup_errors = Off
ignore_repeated_errors = Off
ignore_repeated_source = Off

Posted: Sun Nov 11, 2007 8:13 pm
by Jonah Bron
Thanks, everyone. It works now. I was setting the display_errors and error_reporting on lines 74 and 102. I scrolled down, and found the same settings, (set to Off, of course) on lines 349 and 356. I wonder why :roll:

P.S. sorry for the repeated post. I'm on dialup, and is really slow right now, and posting.php didn't open, so didn't know it was posted anyway. :oops:

Posted: Sun Nov 11, 2007 8:56 pm
by feyd
It's recommended to NEVER turn off E_NOTICE (or any other level for that matter, except maybe E_STRICT.)

This goes doubly on localhost. Remember that on a production server all you need to do is turn display_errors off, but you still want those errors to be logged so KEEP THEM ON.

Posted: Sun Nov 11, 2007 9:01 pm
by Jonah Bron
OK. I have it set to E_ALL. When an error is logged, where is it logged to?

Thanks

Posted: Sun Nov 11, 2007 10:12 pm
by feyd
That would depend on what your error_log setting is.

Posted: Mon Nov 12, 2007 2:55 am
by phpBuddy
Yes.
After each change in php.ini you would have to restart server.
This is true for Apache and most servers. (There are other servers that work differently, though)

Because Apache loads the php.ini settings once.
At server program start.

Posted: Mon Nov 12, 2007 2:56 am
by phpBuddy
feyd wrote:That would depend on what your error_log setting is.
Yes.
And it can be the path to any file you want.
For example: error_log = 'c:/php/mylogs/errors.log'
You have to create the directory /mylogs/, but the file is created automatically.
Just as the other log settings, error_log can be set in your script
which will temporarily override you php.ini setttings.


The settings in beginning of this script will turn Off display errrors
and log all errors happening in this script to a file in same directory instead.

Code: Select all

<?php
error_reporting( E_ALL );
ini_set('display_errors', '0');// ini_set() can change php.ini settings
ini_set('log_errors', '1');    // but will only effect current script
ini_set('error_log', dirname(__FILE__).'/_phperror.log');//directory of this file


// test some errors
include( 'missing.file' );
$hello = 'hello';
echo $helo;

?>

Posted: Mon Nov 12, 2007 12:42 pm
by Jonah Bron
Good. Thanks, feyd, Bogey and phpbuddy :smile: