He's The Man
Novice Spammer
Gender:
Posts: 100
0 credits Members referred : 0
« Reply #8 on: Sep 17, 2005, 07:25:54 PM »
Thats pretty cool, I've never thought of logging my errors.
Novice Spammer
Gender:
Posts: 100
346 credits Members referred : 0
« Reply #9 on: Sep 19, 2005, 11:44:21 PM »
That is a really neat script. I will probaby implement it on my new site.
Global Moderator
Internet Junkie
Gender:
Posts: 1523
6847 credits Members referred : 8
Gimme all your cookies!!!
« Reply #10 on: Oct 04, 2005, 03:57:18 AM »
I had a script on our old server that scanned the error logs every hour and emailed the account owner / tech a list of the php errors that occured in that hour. I will see if I can find it...
if ( $errno != 2 && $errno != 8 )//This line is to avoid simple errors { $db_link = mysql_pconnect("host","user","pass");//Change this line and the next to your settings $db_name = "name_of_my_database";
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8037
41179 credits Members referred : 3
« Reply #12 on: Oct 17, 2005, 03:13:39 AM »
That's a very nice implementation wolf.
I use something simmilar to this in my sites.
The only thing you should check is the mysql_pconnec command, because I think that not every hosting account allow persistant connections, so if you have problem with that you can replace it with mysql_connect(.....
This way the php will log all the errors to this file
Global Moderator
Internet Junkie
Gender:
Posts: 1523
6847 credits Members referred : 8
Gimme all your cookies!!!
« Reply #14 on: Oct 31, 2005, 06:05:27 PM »
OK I have found the script. Feel free to improve it!
Code:
<?php
/** * PHP error logs are stored here: /usr/local/apache/logos/php_error_log * The php.ini file that tells php where to store error logs (at the above location) is this one: /usr/local/lib/php.ini * This script should have 755 permissions for the cPanel crontab to run it. **/
/* This script is designed to email report(s) of new errors written to the server-wide php error log. An error line might look like this:
[29-Oct-2004 12:28:22] PHP Warning: main(header.inc): failed to open stream: No such file or directory in /home/sample/public_html/enquiries.htm on line 7
The aim is to identify each error line by the account name (in this case 'sample'), group together all errors for that account name */
$count = 0; // count of how many new errors since last time this script ran if ($size != $lastsize) // error log is bigger than the last time this script ran, so continue reporting. { $ferrp = fopen(PHP_ERR_FILE, "r"); fseek($ferrp, $lastsize); // Move all the error lines since the last report into $errors $errors = fread($ferrp, $size-$lastsize); fclose ($ferrp);
// Move all the lines into an array for easier processing based on detecting line breaks $a_errors = explode("\n",$errors); $count = count($a_errors); foreach ($a_errors as $key => $line) { if ($line == "") { continue; // blank lines possible - reject these. } $before = ""; $after = ""; $accName = ""; list($before,$after) = explode (" in /home/",$line); list($accName,$theRest)= explode ("/",$after); if ($accName == "") { $accName = "unknown"; } $a_accounts["$accName"][] = $line; // groups all errors for the same account into a multi-dimensional array. }
// Now for the reporting... $count_total = 0; $message_summary = ""; foreach ($a_accounts as $accName => $a_errorLines) { $message = "New php errors on hosting account '$accName' --------START PHP ERRORS---------------------------------------- "; $count = 0; foreach ($a_errorLines as $key => $errorLine) { $count++; $message .= "Err#$count \t $errorLine\r\n\r\n"; // aggregate all error lines for a single account into a single message } $count_total = $count_total + $count; $message_summary .= "$count\t$accName\r\n"; $message .= "--------STOP PHP ERRORS-----------------------------------------
* This is a free, fully automated service. Any php errors detected and logged for your hosting account '$accName' will be forwarded to you. * It's entirely up to you whether or not you choose to act on this information - but we recommend that you do.
Regards, Tech Team ---------------------------------------------------------------- - this report generated by cron job 'check_php_errlog.php' and scheduled using cPanel";
$flag = false; if (is_array($developers)) { foreach ($developers as $devEmail => $accounts) { if (is_array($accounts)) { foreach ($accounts as $account) { if ($account == $accName) { if ($devEmail != "null-route") { mail($devEmail, "$accName: new PHP errors",$message);// send one email report per account } $flag = true; } } } } }
if ($flag == false) { mail(PHP_ERR_MAILTO, "$accName: new PHP errors",$message);// send one email report per account } } }