Forum Moderators: coopster

Message Too Old, No Replies

Showing errors in PHP

         

csdude55

9:01 am on May 7, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm rebuilding my site using a subdomain as the sandbox, and nobody can see this section but me.

I have display_errors turned off in php.ini, but I don't remember if that's a default setting or something that I changed at some point. My last major rebuild was 2013, so it's been awhile since I needed this.

So the question is, if I turn on display_errors, are my regular users going to see PHP warnings on live pages, or does it only work if I add this to the top of the page:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


Is this even what I'm looking for? Specifically, I have a very long script that's throwing a 500 error, and it would be nice if the system could show me where the problem is.

If turning on display_errors is going to start showing errors everywhere, is there a way to make it just work on this subdomain?

TIA!

robzilla

9:39 am on May 7, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if I turn on display_errors, are my regular users going to see PHP warnings

If you turn it on in php.ini, then yes, everyone will see your errors (unless overridden again with ini_set) -- it's a system-wide setting. If you use the ini_set() function within a script, you are configuring a setting only for the run duration of the script. If you can SSH into the server, you can also 'tail -f' your error log; this keeps the errors separate from the output in your browser.

Peter_S

10:01 am on May 7, 2017 (gmt 0)

5+ Year Member Top Contributors Of The Month



You can also use "set_error_handler" [ [php.net...] ] to define your own function to handle error. Like that you can display error messages yourself for example.

smallcompany

8:28 pm on May 7, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is what I do for PHP errors, not to show them, but have them written into a text file:

; Supress PHP Errors
display_startup_errors = off
display_errors = off
html_errors = off
docref_root = 0
docref_ext = 0
; PHP Error Logging
log_errors = on
error_reporting = 6135
error_log = /someserverpath/phperror.txt


The above is from my .user.ini file. Depending on your server configuration, you may use .htaccess, not sure.

Then, I have a cron job setup to email me every morning, showing the size of the error log which tells me if something has changed or not.

I hope this helps.

Cheers!

csdude55

8:50 pm on May 7, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the help, guys.

Sometimes, I get an error_log file in the same directory as the PHP script with the error, which is helpful... but sometimes I don't. Yesterday I discovered a 20M file with a whole lot of PHP warnings, so I know that option isn't turned off, but I'm not seeing that error log in the directory with the script I'm currently working on.

@smallcompany, my config looks similar to yours, but under error_reporting I have:

E_ALL & ~E_NOTICE & ~E_DEPRECATED


I'm making a guess that this means to show all errors except for E_NOTICE and E_DEPRECATED?

And error_log is just set to error_log (no path).

smallcompany

10:47 pm on May 7, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you tell it where is your error log file, it'll always log it there, so you don't need to search for log files. 6135 should be E_ALL without E_NOTICE.
Looks like setting the location for your PHP error log file would help you.