Forum Moderators: coopster
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
As for the function that will locate and give exactly the error, i do not have any idea.
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.
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
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.