[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

PHP ERROR Message

Can someone send me or point out a really "Hardy" error reporting script that will email me when there is an error in my script, with line number and everything?

Thank you in advance.
0
rgranlund
Asked:
rgranlund
1 Solution
 
Ray PaseurCommented:
I have to teach a PHP class today, so I can't write it out for you, but here is a strategy that I have used in the past, and that has worked very, very well.

I have a CRON job that runs once per second.  It reads all of the files in all of my web root directories (I used all but you might omit images, videos, etc.) into a data string, and makes an md5() digest from the string.  Then it reads a "checkpoint" file that contains the last md5() digest.  If the two strings are the same, it dies silently.
http://php.net/manual/en/function.md5.php
http://php.net/manual/en/function.die.php

However if the md5() strings are not the same, something has changed in the web directory tree.  This change could be the result of me updating a script, in which case I will expect a message.  Or it could be the result of a hack (!) or the output of an error_log().  In that case the script will send an email message using mail().  Then it writes the new md5() string into the checkpoint file before it dies.
http://php.net/manual/en/function.error-log.php
http://php.net/manual/en/function.mail.php

So to bring the pieces together, here is what you do...

1. Set error_reporting(E_ALL)
2. Set display errors off (see ini_set() for more information)
3. Set log errors on
4. Set up your CRON job to monitor the error log file
5. Start the CRON and trigger an error to test the setup.
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/function.ini-set.php
http://php.net/manual/en/errorfunc.configuration.php#ini.error-log
0
 
Olaf DoschkeSoftware DeveloperCommented:
Nice idea, Ray,

also for hacks. It doesn't help to protect from hacks of a database, but that's also not applicable as data isn't meant to be static. There are other indicators to watch about that and it's a topic of it's own.
It's  a nice security measure to check all the static parts of a web site remain static.

Bye, Olaf.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now