Page 1 of 1
PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 3:51 pm
by jarofgreen
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 ...
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 4:57 pm
by VladSun
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.
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 5:11 pm
by jarofgreen
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.
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 5:27 pm
by Eran
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
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 5:45 pm
by jarofgreen
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.
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 5:51 pm
by Eran
Unfortunately, a custom error handler can't catch fatal errors. By definition, they kill the PHP process
Re: PHP Error Reporting and Logging Service
Posted: Fri Oct 01, 2010 5:58 pm
by jarofgreen
Yeah. Still, it could catch a lot.
Re: PHP Error Reporting and Logging Service
Posted: Sat Oct 02, 2010 4:07 am
by jarofgreen
Am working on a very basic first version now ...

Re: PHP Error Reporting and Logging Service
Posted: Sat Oct 02, 2010 6:29 am
by jarofgreen
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.
Code: Select all
ElastikRemoteErrorReportingServiceWidget::$SiteID = 1;
ElastikRemoteErrorReportingServiceWidget::$SiteSecurityKey = "1234";
ElastikRemoteErrorReportingServiceWidget::$SiteHost = "127.0.0.1:4000";
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)
Code: Select all
ElastikRemoteErrorReportingServiceWidget::$includeCookies = false;
ElastikRemoteErrorReportingServiceWidget::$ignoreNotice = true;
You can ping the server, and then check on the server that it was recorded correctly:
Code: Select all
ElastikRemoteErrorReportingServiceWidget::pingServer();
Or just start error trapping:
Code: Select all
ElastikRemoteErrorReportingServiceWidget::setUpErrorReporting();
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

Re: PHP Error Reporting and Logging Service
Posted: Sun Oct 31, 2010 4:16 am
by jarofgreen
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!
Re: PHP Error Reporting and Logging Service
Posted: Thu Jan 27, 2011 5:00 pm
by jarofgreen
Eran wrote:Unfortunately, a custom error handler can't catch fatal errors. By definition, they kill the PHP process
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.
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 ...