Forum Moderators: coopster

Message Too Old, No Replies

customizing php debug messages

         

jojy

2:53 am on Dec 30, 2008 (gmt 0)

10+ Year Member



Hello,
I have been trying to resolve a fatal error on my website but couldn't get luck because I don't know where this error is actually occurring.. Let me explain it

I am dumping all php errors into a txt file so php does not display notices and errors to users here is what i am doing..

ini_set('error_reporting', E_ALL);
ini_set('log_errors',TRUE);
ini_set('html_errors',FALSE);
ini_set('error_log',"path/to/my/log.txt");

A page is causing a fatal error and I am unable to track it because I do not which page is this.. here is the error I am getting

PHP Notice: Constant SITE already defined in /home/web/folder/configuration.php on line 2
PHP Fatal error: Cannot redeclare class dbcls in /home/web/folder/functions/dbcls.php on line 188 (its the end of file)

all these two errors occur at the same time. 5 people checked thoroughly site but couldn't found any error..

I remember a search engine was picking up a wrong pagination string and the htaccess rule was allowing this and it was causing the database error since it was the db error so I tracked it using this php code in database wrapper class $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

This tell me the exact page where error occurred.. is there any possibility to do same thing in php? I mean can we customize the errors.. and add some more info in it?

Thanks for reading this long message

rockerzz501

3:27 am on Dec 30, 2008 (gmt 0)

10+ Year Member



It is hard to troubleshoot issues if you are seeing it as a whole. In my case, I divide the whole system into sections, then I try to enable each section while disabling others, in this case i can see which section is causing issues and can easily isolate it from the rest of the system.

As for the function that will locate and give exactly the error, i do not have any idea.

jojy

11:03 am on Dec 30, 2008 (gmt 0)

10+ Year Member



I did exactly that.. checked site functions individually but no luck. Thought I could customize the php error settings

penders

2:12 pm on Dec 30, 2008 (gmt 0)

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



You don't appear to have a syntax error... it sounds as if you are trying to include the same file(s) more than once (but PHP cannot determine the exact location that this occurs as it seems the error occurs in the included file, not the file it is being included into?). Perhaps you are including files that in turn include other files which in turn include the same file?! May be the use of include_once() would sort this? Are you using output buffering?

jojy

3:27 pm on Dec 30, 2008 (gmt 0)

10+ Year Member



Yes it appears the file is included more than once and I am controlling it using constant to not to include that file.. see the first error is constant and the second one is fatal error.

I checked all code but couldn't found any leak.. and yes I am using output buffering..

include_once and require_once are not recommended on under heavy traffic websites.

jojy

11:24 pm on Dec 31, 2008 (gmt 0)

10+ Year Member



is there any way to stop preventing php execution at end of the file?

Example
/*class: myapp.php*/
if(!defined('ACONST')) {
require("loader.php");
exit;
}
class myapp {
}

/*file: loader.php*/
require("myapp.php");

now if you myapp.php the web server will restart and in apache log you will see this error can't redeclare class myapp.php

penders

6:06 pm on Jan 2, 2009 (gmt 0)

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



include_once and require_once are not recommended on under heavy traffic websites.

include_once() no doubt takes marginally more time than include() but how much? Particularly if you are having to write additional code anyway in order to prevent the same file being included more than once? is it really something to avoid?

/*class: myapp.php*/  
if(!defined('ACONST')) {
require("loader.php");
exit;
}
class myapp {
}

Yes, you can do this sort of thing (I assume ACONST is defined in loader.php?). exit will halt execution and prevent any calling units from finishing, so return may be more preferable? However, particularly if your unit contains just the class definition, it might be better to use the class_exists() function rather than rely on a constant being defined. Or even use PHP5's __autoload() (is there much of an overhead with this?) to include your classes.