PHP Error Reporting and Logging Service
Moderator: General Moderators
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
PHP Error Reporting and Logging Service
I've seen reporting tools for other languages. You put in a small file to your project with basic settings, and any errors are picked up and reported to a central server by a HTTP API Call. On the central server they are logged, duplicate errors collated, and developers warned by email. Does anyone know of such a service?
If not, I'm tempted to do one myself as an open source package ...
If not, I'm tempted to do one myself as an open source package ...
Re: PHP Error Reporting and Logging Service
Basically you could delegate the apache log output processing to an external command which in turn could send these logs to a remote machine, archive them, examine them and send alerts. All you have to do is:
[text]CustomLog "|/path/your_logger" common[/text] in your apache config file.
[text]CustomLog "|/path/your_logger" common[/text] in your apache config file.
There are 10 types of people in this world, those who understand binary and those who don't
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Hmm. If you do it in PHP, you could pull out info to include in the error report - variable info, stack trace, environment info, $_POST and so on.
EDIT:
Altho I don't know how much info CustomLog gets ... and I want this to work on Apache and IIS.
EDIT:
Altho I don't know how much info CustomLog gets ... and I want this to work on Apache and IIS.
Re: PHP Error Reporting and Logging Service
Zend Server does this for you. It's not free though. http://www.zend.com/en/products/server/#Monitoring
Also, you use exceptions you can have an alert sent in the catch{} block
Also, you use exceptions you can have an alert sent in the catch{} block
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Zend eh? Hmmm.
I was thinking of using set_error_handler and set_exception_handler to catch as many runtime errors as possible.
I've done something rough like this before ... thinking it wouldn't be to hard to do a good job.
I was thinking of using set_error_handler and set_exception_handler to catch as many runtime errors as possible.
I've done something rough like this before ... thinking it wouldn't be to hard to do a good job.
Re: PHP Error Reporting and Logging Service
Unfortunately, a custom error handler can't catch fatal errors. By definition, they kill the PHP process
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Yeah. Still, it could catch a lot.
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Am working on a very basic first version now ... 
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
OK, have a basic working start ... I'll keep the code quiet for now* as it's not finished yet.
But I wanted to show you the widget that collects and sends errors and get your comments.
On the site you want to collect errors from, include this file.
http://elastik.svn.sourceforge.net/view ... xt%2Fplain
Then set up the location and access of the server.
You can then do additional config: (Some ppl may consider logging Cookies a security problem, and some ppl aren't as anal about trapping Notices as I am)
You can ping the server, and then check on the server that it was recorded correctly:
Or just start error trapping:
I've seen some stuff online about trapping fatal errors using output caching; I'll pass on that but others could add it easily
I'm aware not everyone has CURL installed ... we could also see about using fopen (if URLs are allowed) or even fsockopen as a last resort.
Comments and feedback?
Thanks,
James
* Altho anyone half decent could find the code now I've posted a link to the repository ... oh well
But I wanted to show you the widget that collects and sends errors and get your comments.
On the site you want to collect errors from, include this file.
http://elastik.svn.sourceforge.net/view ... xt%2Fplain
Then set up the location and access of the server.
Code: Select all
ElastikRemoteErrorReportingServiceWidget::$SiteID = 1;
ElastikRemoteErrorReportingServiceWidget::$SiteSecurityKey = "1234";
ElastikRemoteErrorReportingServiceWidget::$SiteHost = "127.0.0.1:4000";Code: Select all
ElastikRemoteErrorReportingServiceWidget::$includeCookies = false;
ElastikRemoteErrorReportingServiceWidget::$ignoreNotice = true;Code: Select all
ElastikRemoteErrorReportingServiceWidget::pingServer();Code: Select all
ElastikRemoteErrorReportingServiceWidget::setUpErrorReporting();I'm aware not everyone has CURL installed ... we could also see about using fopen (if URLs are allowed) or even fsockopen as a last resort.
Comments and feedback?
Thanks,
James
* Altho anyone half decent could find the code now I've posted a link to the repository ... oh well
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Going on holiday and deadlines got in the way ... sorry (But in that British way were what we actually mean "Sorry, only not sorry at all, because holiday was great fun")
But I didn't forget, and now a working service is ready for testing:
http://sourceforge.net/news/?group_id=317819&id=293422
Documentation on how to set up monitoring is at:
http://elastik.svn.sourceforge.net/view ... ervice.txt
I'll be working on more details for it today ... any comments welcome!
But I didn't forget, and now a working service is ready for testing:
http://sourceforge.net/news/?group_id=317819&id=293422
Documentation on how to set up monitoring is at:
http://elastik.svn.sourceforge.net/view ... ervice.txt
I'll be working on more details for it today ... any comments welcome!
-
jarofgreen
- Forum Commoner
- Posts: 71
- Joined: Sun Jul 11, 2010 12:40 pm
Re: PHP Error Reporting and Logging Service
Not true apparently ... using a combination off http://uk2.php.net/register_shutdown_function and http://uk3.php.net/error_get_last I have been able to catch fatal Errors.Eran wrote:Unfortunately, a custom error handler can't catch fatal errors. By definition, they kill the PHP process
Here is some heavily truncated code:
Code: Select all
register_shutdown_function('x');
function x() {
$error = error_get_last();
if ($error) {
// deal with $error['file'],$error['line'],$error['message'],$error['type']
}
}
Full code for my error reporting widget is at http://elastik.svn.sourceforge.net/view ... xt%2Fplain or should be, not sure if sf.net is having problems at the moment ...