0

For some inexplicable reason my PHP wont display errors. I have been writing a script that I am now testing and debugging but all I get is a white page even when I stick an echo 1; on line 1. At the top of my document I have the following error overrides to try and get errors to display:

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

I can't change the global php.ini file as this would override the settings for other live sites.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Steve Smith
  • 734
  • 6
  • 14
  • 29
  • If it is a hosting company, there are many methods like `suhosin` to display the errors. Connect with them, so that they can guide you better. – Praveen Kumar Purushothaman Dec 07 '12 at 11:23
  • it is an unmanaged vps, I have ssh access and I believe suhosin is installed. I don't know how to get this to display errors for me though... – Steve Smith Dec 07 '12 at 11:33
  • You have shell access and couldn't change PHP.ini? – Praveen Kumar Purushothaman Dec 07 '12 at 11:34
  • What PHP version? - I've had trouble before with older versions not reporting Parse Errors correctly. Recently I deployed a script with the `const` keyword in it to a machine that was still running 5.1. Full error reporting turned on did __not__ help, nothing in the logs, nada. – Leigh Dec 07 '12 at 11:36
  • php version 5.3.13. I didn't say I physically couldnt change the php.ini I said I couldnt change it without it affecting other live sites on the server. I can't have errors popping up everywhere on other sites while I debug this script when I should just be able to turn on error displaying for this one process.... – Steve Smith Dec 07 '12 at 11:39
  • White page with simply ` – Leigh Dec 07 '12 at 11:42
  • you can set php.ini values in a htaccess file. that might solve your "can't change php.ini" issue, and also might be a place to look for causes for the problems. – SDC Dec 07 '12 at 11:43
  • I said I put an echo 1; at the top of the script and get nothing, obviously if I have a php script of just then it displays a 1. Effectively there iz a runtime error due to probably a syntax issue somwhere but without erros I can't get PHP to tell me where it is to fix it – Steve Smith Dec 07 '12 at 11:43
  • SDC - the server is running cpanel so htaccess error rewrites aren't allowed. Massive pain as this is the way I would usually do it yeah. – Steve Smith Dec 07 '12 at 11:44
  • What will be the output of `ini_get("display_errors");` after your ini_set functions? Could be you have no permissions for changing ini configuration through the php file. – ozahorulia Dec 07 '12 at 11:44
  • it wouldn't be an error rewrite; it would just be an ini setting. – SDC Dec 07 '12 at 11:45
  • even without php displaying the error, you should still be able to get the error message out of the server logs. Also, have you tried running the same php file on your local machine? if there's a syntax error, you should be able to pick it up without having to run it on the server. – SDC Dec 07 '12 at 11:46
  • SDC - yeah I know how to do it, my point stands though – Steve Smith Dec 07 '12 at 11:46

2 Answers2

10

Try to include failing script in another php file like:

error_reporting(E_ALL);
ini_set("display_errors", 1);
include('script_that_fails.php');

EDIT

Short explanation:

If main script contains for example syntax error and environment has error reporting turned off, then even if in main script we'll enable error reporting then it won't success as script won't be executed (because of syntax error). Small trick described above allows to enable error reporting and see the error.

lupatus
  • 4,208
  • 17
  • 19
  • 1
    who the hell just downvoted this, the guy is a genius. the script itself doesnt get chance to reset the php values to display errors because of a runtime error, including it in a separate file as above allows it to sort the display errors then hit the runtime issue. Genius mate well done – Steve Smith Dec 07 '12 at 11:46
  • standard, guy puts the right answer up. gets insta down voted – Steve Smith Dec 07 '12 at 11:53
  • Guys, I'm too sorry, I firstly got the answer wrong. Just edit your answer to let me vote again. – ozahorulia Dec 07 '12 at 20:09
  • Just had the same prob and lupatus reply helped me to resolve it. Another user explained: "...For parsing errors it's too late to enable error_reporting in the invalid script itself, since not even the first line will be run. PHP will abort before seeing the ini_set() or error_reporting(). PHP doesn't interpret scripts line-wise. ..." which made it more clear to me than lupatus words. :) – MBaas Jan 06 '13 at 15:09
1

Try this

set_error_handler("var_dump");

This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions (using trigger_error()).

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252