<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Automatically monitor and email PHP error log content</title>
	<atom:link href="http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/</link>
	<description>PHP web developer // Melbourne, AU</description>
	<lastBuildDate>Mon, 09 Nov 2009 19:52:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Automatically monitor and email PHP error log content &#124; Errors &#38; Geeks</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-747</link>
		<dc:creator>Automatically monitor and email PHP error log content &#124; Errors &#38; Geeks</dc:creator>
		<pubDate>Mon, 29 Jun 2009 15:28:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-747</guid>
		<description>[...] the original here: Automatically monitor and email PHP error log content Tags: photography, PHP, [...]</description>
		<content:encoded><![CDATA[<p>[...] the original here: Automatically monitor and email PHP error log content Tags: photography, PHP, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-462</link>
		<dc:creator>James</dc:creator>
		<pubDate>Tue, 17 Mar 2009 22:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-462</guid>
		<description>Hi Brian,

Thanks for your contribution. My main motivation for the error log archive is so that if in between error log check runs, which are say every 5 minutes, a lot of errors are recorded, only the first few get emailed so as to avoid clogging up inbox space. Once the full archive is reviewed by an admin, I envisaged it more often than not being cleared, or at least moved elsewhere. You have a valid point though and particularly if a high traffic site has a lot of PHP errors, the log file could fill quite quickly.

To keep the naming of the archive file in line with the original file name (as defined by the admin), I&#039;d suggest something like this:

$sHistoricalLogName = sprintf(&#039;%s.%s.archive&#039;, ERROR_LOG_FILE, date(&#039;Y-m-d&#039;));

or for monthly archives:

$sHistoricalLogName = sprintf(&#039;%s.%s.archive&#039;, ERROR_LOG_FILE, date(&#039;Y-m&#039;));

James</description>
		<content:encoded><![CDATA[<p>Hi Brian,</p>
<p>Thanks for your contribution. My main motivation for the error log archive is so that if in between error log check runs, which are say every 5 minutes, a lot of errors are recorded, only the first few get emailed so as to avoid clogging up inbox space. Once the full archive is reviewed by an admin, I envisaged it more often than not being cleared, or at least moved elsewhere. You have a valid point though and particularly if a high traffic site has a lot of PHP errors, the log file could fill quite quickly.</p>
<p>To keep the naming of the archive file in line with the original file name (as defined by the admin), I&#8217;d suggest something like this:</p>
<p>$sHistoricalLogName = sprintf(&#8216;%s.%s.archive&#8217;, ERROR_LOG_FILE, date(&#8216;Y-m-d&#8217;));</p>
<p>or for monthly archives:</p>
<p>$sHistoricalLogName = sprintf(&#8216;%s.%s.archive&#8217;, ERROR_LOG_FILE, date(&#8216;Y-m&#8217;));</p>
<p>James</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-461</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 16 Mar 2009 23:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-461</guid>
		<description>Thanks this works very well, (so far at least.)

One problem I think might happen with your original script is the archive log could become big enough to crash some file systems, (over 2 gig) eventually.

I&#039;ve changed the last section to avoid this:

/**
 * We&#039;ll copy the full content of the error log to an archive. This is useful for a number
 * of reasons, not least because we are only emailing a portion of the original errors if
 * the log file was larger than our given MAX_CONTENT_SIZE - there could be errors in the
 * full log not included in the email.
 */
$sHistoricalLogName = &#039;&lt;&gt;\\archive\\&#039; . date(&#039;Y-m-d&#039;) . &#039;.log&#039;;

$sFullContent = sprintf(&quot;----- Full content of error log as mailed @ %s -----\n%s\n&quot;, date(&#039;d/m/Y H:i:s&#039;), $sFullContent);

file_put_contents($sHistoricalLogName, $sFullContent, FILE_APPEND);

/**
 * And we&#039;re done.
 */</description>
		<content:encoded><![CDATA[<p>Thanks this works very well, (so far at least.)</p>
<p>One problem I think might happen with your original script is the archive log could become big enough to crash some file systems, (over 2 gig) eventually.</p>
<p>I&#8217;ve changed the last section to avoid this:</p>
<p>/**<br />
 * We&#8217;ll copy the full content of the error log to an archive. This is useful for a number<br />
 * of reasons, not least because we are only emailing a portion of the original errors if<br />
 * the log file was larger than our given MAX_CONTENT_SIZE &#8211; there could be errors in the<br />
 * full log not included in the email.<br />
 */<br />
$sHistoricalLogName = &#8216;&lt;&gt;\\archive\\&#8217; . date(&#8216;Y-m-d&#8217;) . &#8216;.log&#8217;;</p>
<p>$sFullContent = sprintf(&#8220;&#8212;&#8211; Full content of error log as mailed @ %s &#8212;&#8211;\n%s\n&#8221;, date(&#8216;d/m/Y H:i:s&#8217;), $sFullContent);</p>
<p>file_put_contents($sHistoricalLogName, $sFullContent, FILE_APPEND);</p>
<p>/**<br />
 * And we&#8217;re done.<br />
 */</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-431</link>
		<dc:creator>James</dc:creator>
		<pubDate>Tue, 10 Feb 2009 01:05:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-431</guid>
		<description>Hi Duddy,

The script needs write permissions on the log file so that it can truncate the contents using : file_put_contents(ERROR_LOG_FILE,null);. If the user running the script doesn&#039;t have write permissions, the script will fail to truncate the file and then the next time it runs it will send the same content all over again.

As for only sending an email when the string [ERROR] is present, I would add in some code after the line :

$sContent = $sFullContent = file_get_contents(ERROR_LOG_FILE);

that explodes $sContent on new lines creating an array with each line as an array element. I&#039;d then iterate through those elements pattern matching for &#039;[ERROR]&#039; and for each line containing a match I&#039;d add it to a new variable, perhaps $sContentMatched (.= $sMatchingLine). Once all the content has been checked, I&#039;d then set $sContent and $sFullContent to equal $sContentMatched and then allow the script to continue as normal, though you&#039;ll want to check that you actually have matching content first, and if not tell the script to exit.</description>
		<content:encoded><![CDATA[<p>Hi Duddy,</p>
<p>The script needs write permissions on the log file so that it can truncate the contents using : file_put_contents(ERROR_LOG_FILE,null);. If the user running the script doesn&#8217;t have write permissions, the script will fail to truncate the file and then the next time it runs it will send the same content all over again.</p>
<p>As for only sending an email when the string [ERROR] is present, I would add in some code after the line :</p>
<p>$sContent = $sFullContent = file_get_contents(ERROR_LOG_FILE);</p>
<p>that explodes $sContent on new lines creating an array with each line as an array element. I&#8217;d then iterate through those elements pattern matching for &#8216;[ERROR]&#8216; and for each line containing a match I&#8217;d add it to a new variable, perhaps $sContentMatched (.= $sMatchingLine). Once all the content has been checked, I&#8217;d then set $sContent and $sFullContent to equal $sContentMatched and then allow the script to continue as normal, though you&#8217;ll want to check that you actually have matching content first, and if not tell the script to exit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duddy</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-430</link>
		<dc:creator>Duddy</dc:creator>
		<pubDate>Mon, 09 Feb 2009 17:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-430</guid>
		<description>Hi,

thanks for this - i assume it will work on MySql logs just the same, however what i would like is a way that an email will be sent only when the string [ERROR] has been added to the MySql log. Also, i am not sure why in this script it needs to have WRITE permissions.

Thanks
Duddy</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>thanks for this &#8211; i assume it will work on MySql logs just the same, however what i would like is a way that an email will be sent only when the string [ERROR] has been added to the MySql log. Also, i am not sure why in this script it needs to have WRITE permissions.</p>
<p>Thanks<br />
Duddy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-411</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 22 Oct 2008 09:56:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-411</guid>
		<description>Hi Murray,

If you ensure PHP_errors.log.archive is in the directory the script is looking for it and the permissions on it (the file) are 0666 (read and write for all), I don&#039;t see why there should be any problem, regardless of who owns the file. Confusingly you have said the file exists and is owned by nobody, which indicates the system has had no problem creating the error log archive file.

Without seeing your adjusted version of this script it is hard for me to comment or provide any further suggestions.

James</description>
		<content:encoded><![CDATA[<p>Hi Murray,</p>
<p>If you ensure PHP_errors.log.archive is in the directory the script is looking for it and the permissions on it (the file) are 0666 (read and write for all), I don&#8217;t see why there should be any problem, regardless of who owns the file. Confusingly you have said the file exists and is owned by nobody, which indicates the system has had no problem creating the error log archive file.</p>
<p>Without seeing your adjusted version of this script it is hard for me to comment or provide any further suggestions.</p>
<p>James</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Murray</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-410</link>
		<dc:creator>Murray</dc:creator>
		<pubDate>Wed, 22 Oct 2008 09:01:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-410</guid>
		<description>Hi James,

thanks for this script, after a little fiddling around I got it working, however there is a persistent error with the permissions when creating the log archive:

[21-Oct-2008 23:30:02] PHP Warning:  file_put_contents(/home/....../PHP_errors.log.archive) [function.file-put-contents]: failed to open stream: Permission denied in /home/....../error.log.php on line 175

I&#039;ve chmod 0777 and tried what I can to give it correct permissions, the file is created and owned by nobody - do you know what I can do to correct this?

thanks in advance.</description>
		<content:encoded><![CDATA[<p>Hi James,</p>
<p>thanks for this script, after a little fiddling around I got it working, however there is a persistent error with the permissions when creating the log archive:</p>
<p>[21-Oct-2008 23:30:02] PHP Warning:  file_put_contents(/home/&#8230;&#8230;/PHP_errors.log.archive) [function.file-put-contents]: failed to open stream: Permission denied in /home/&#8230;&#8230;/error.log.php on line 175</p>
<p>I&#8217;ve chmod 0777 and tried what I can to give it correct permissions, the file is created and owned by nobody &#8211; do you know what I can do to correct this?</p>
<p>thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-172</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 15 Sep 2008 23:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-172</guid>
		<description>Thanks for putting the effort in to create this nifty utility. I was pulling my hair out thinking of ways to code a custom error handler to send email alerts; this is a far better solution.</description>
		<content:encoded><![CDATA[<p>Thanks for putting the effort in to create this nifty utility. I was pulling my hair out thinking of ways to code a custom error handler to send email alerts; this is a far better solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hunter</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-127</link>
		<dc:creator>Hunter</dc:creator>
		<pubDate>Thu, 07 Aug 2008 04:08:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-127</guid>
		<description>Thanks. This could literally save my career. (Parse errors are evil little suckers).</description>
		<content:encoded><![CDATA[<p>Thanks. This could literally save my career. (Parse errors are evil little suckers).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Starr</title>
		<link>http://www.jamescaws.com/2008/07/automatically-email-php-error-log-content/comment-page-1/#comment-120</link>
		<dc:creator>Jeff Starr</dc:creator>
		<pubDate>Wed, 16 Jul 2008 16:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.jamescaws.co.uk/?p=32#comment-120</guid>
		<description>Thanks for the script! This is incredibly useful for anyone looking to keep a close eye on their PHP errors. I track any/all PHP errors through a log file on the server that I check every few days, but having the information sent directly to my mobile account is definitely more convenient. Great work!</description>
		<content:encoded><![CDATA[<p>Thanks for the script! This is incredibly useful for anyone looking to keep a close eye on their PHP errors. I track any/all PHP errors through a log file on the server that I check every few days, but having the information sent directly to my mobile account is definitely more convenient. Great work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
