PHP Error Reporting and Logging Service

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

PHP Error Reporting and Logging Service

Post 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 ...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP Error Reporting and Logging Service

Post 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.
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

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Error Reporting and Logging Service

Post 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
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: PHP Error Reporting and Logging Service

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Error Reporting and Logging Service

Post by Eran »

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

Post by jarofgreen »

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

Post by jarofgreen »

Am working on a very basic first version now ... :D
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: PHP Error Reporting and Logging Service

Post 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 :-)
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: PHP Error Reporting and Logging Service

Post 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!
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: PHP Error Reporting and Logging Service

Post 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 ...
Post Reply