<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>High Fibre Programming &#187; Linux</title>
	<atom:link href="http://www.4pmp.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.4pmp.com</link>
	<description>PHP, MySQL, C, Java, Linux and other great after dinner speech topics</description>
	<lastBuildDate>Tue, 17 Jan 2012 09:10:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Daemonize PHP (properly)</title>
		<link>http://www.4pmp.com/2011/02/daemonize-php-properly/</link>
		<comments>http://www.4pmp.com/2011/02/daemonize-php-properly/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 21:39:35 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[multiprocessing]]></category>
		<category><![CDATA[multitasking]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=403</guid>
		<description><![CDATA[There is often a need when building a website to automate background processes, for example: Sending emails: many sites don&#8217;t immediately connect to an SMTP server when a user fires off an email request, but rather store the email in the database which is processed by a background process, thus decoupling the frontend from the [...]]]></description>
			<content:encoded><![CDATA[<p>There is often a need when building a website to automate background processes, for example:</p>
<ul>
<li><strong>Sending emails:</strong> many sites don&#8217;t immediately connect to an SMTP server when a user fires off an email request, but rather store the email in the database which is processed by a background process, thus decoupling the frontend from the SMTP server.   If the SMTP server goes down, your users can still register</li>
<li><strong>Offline processing:</strong> let&#8217;s say your site has a social element to it, users have real-time news feeds that get updated whenever their friends do things on your site.   By updating these feeds offline there&#8217;s no need for users to wait until all 1,000,000 of their friends&#8217; feeds have been updated before completing a request to post a simple comment.</li>
</ul>
<p>There are plenty more examples, in fact as a rule of thumb it&#8217;s best to do everything that doesn&#8217;t have to be done immediately on a HTTP request later in the background.   It also helps manage peak traffic, when your site is overloaded, just don&#8217;t run the background tasks until the peak has gone.   Ok, so news feeds aren&#8217;t bang up-to-date for a short period, but at least the site works.   So how does one go about automating all these background tasks?</p>
<h3>CRON</h3>
<p>This is probably the first port-of-call; implement your background task in PHP, thereby enabling you to use the database abstraction layer and all the other libraries in your application, and set CRON to run the script every minute.</p>
<p>Great – everything works perfectly, that is until the data in your database grows so big that the tasks start taking longer than one minute and you end up with lots of tasks all running at the same time – and potentially all processing the same data!   Ooops, the boss just got his registration email ten times.</p>
<p>So you could implement some sort of locking mechanism to prevent multiple instances but it&#8217;s all starting to get a bit fragile with lots of interdependencies – all you want to do is run a simple script!</p>
<h3>Write a daemon in PHP</h3>
<p>So it&#8217;s back to the drawing board – what is needed is a daemon that will sit in the background and run as script continually, restarting it immediately after it finishes.   You could write a daemon in PHP – this would enable you to write a daemon which would interface well with your existing PHP scripts, there are even some good PHP packages which make writing a daemon in PHP easy.</p>
<p>So, full of enthusiasm you launch into writing your own daemon in PHP.   A week or so later, after reading all about process control, (and probably pulling large chunks of hair out in the process as yo realise it wasn&#8217;t as simple as you thought), you finally have something that works.   You deploy it to your website, sit back and feel smug.</p>
<p>After a week your boss rages into your office demanding to know why nobody has registered in the past week.   Red faced, you go to check your PHP daemon that sends emails form the email queue is still running – and it isn&#8217;t.   If you haven&#8217;t already been fired then your next step would probably be to find out what happened.   Looking through your PHP error log you find a “FATAL ERROR” from your daemon script, dated exactly one week ago.</p>
<p>PHP can throw fatal errors for all sorts of reasons, and there&#8217;s no way to recover from them.   Also, PHP is renowned for its rather flaky <a title="PHP Garbage Collection" href="http://www.php.net/manual/en/features.gc.performance-considerations.php">memory management</a> – whilst this is fine for web scripts that render a page and then end, it makes it highly unsuitable to write applications.</p>
<h3>Enter The Fat Controller</h3>
<p>How can we solve the problem?   We need to run PHP scripts as a daemon.   I faced this problem one year ago and I solved it by writing The Fat Controller.   It is a program written in C that runs a daemon and can continually run PHP scripts.   As it is written in C, it is highly stable and can run for months or years without problem.   As the daemon runs separately from the PHP scripts, no matter what happens in the PHP script, it does not affect the Fat Controller.</p>
<p>The Fat Controller is also very flexible, easy to install and configure and supports running multiple instances of a PHP at the same time to achieve parallel processing.   You can even configure it to dynamically control the number of parallel processes dependent on how much work there is.</p>
<p>You can read more about The Fat Controller here   <a title="The Fat Controller" href="http://www.4pmp.com/fatcontroller/">http://www.4pmp.com/fatcontroller/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2011/02/daemonize-php-properly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>svn: &#8216;http://subversion.tigris.org/xmlns/dav/md5-checksum&#8217; was not present on the resource</title>
		<link>http://www.4pmp.com/2010/10/svn-httpsubversion-tigris-orgxmlnsdavmd5-checksum-was-not-present-on-the-resource/</link>
		<comments>http://www.4pmp.com/2010/10/svn-httpsubversion-tigris-orgxmlnsdavmd5-checksum-was-not-present-on-the-resource/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 21:53:34 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=331</guid>
		<description><![CDATA[I recently got this somewhat cryptic error message when trying to merge something in Subversion. In the root directory of my working copy, I ran svn merge, something along the lines of: svn merge -c 1234 http://svn.example.com/myproject/trunk ./ Only to get: svn: 'http://subversion.tigris.org/xmlns/dav/md5-checksum' was not present on the resource I had absolutely no idea what [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got this somewhat cryptic error message when trying to merge something in Subversion.   In the root directory of my working copy, I ran svn merge, something along the lines of:</p>
<p><code>svn merge -c 1234 http://svn.example.com/myproject/trunk ./</code></p>
<p>Only to get:<br />
<code>svn: 'http://subversion.tigris.org/xmlns/dav/md5-checksum' was not present on the resource</code></p>
<p>I had absolutely no idea what it was on about, and a fair bit of Googling turned up nothing.   Then, just for fun, I tried going one level up from my working copy and trying again:</p>
<p><code><br />
cd ../<br />
svn merge -c 1234 http://svn.example.com/myproject/trunk ./myworkingcopy/<br />
</code></p>
<p>And lo and behold &#8211; it worked.   I haven&#8217;t the foggiest idea why, but it does.   Any ideas anyone?</p>
<p><em>Using SVN v1.6.6</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2010/10/svn-httpsubversion-tigris-orgxmlnsdavmd5-checksum-was-not-present-on-the-resource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect and append STDOUT and STDERR to a log file</title>
		<link>http://www.4pmp.com/2010/06/redirect-and-append-stdout-and-stderr/</link>
		<comments>http://www.4pmp.com/2010/06/redirect-and-append-stdout-and-stderr/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 11:08:08 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[stderr]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=309</guid>
		<description><![CDATA[Redirecting STDOUT to a file is easy: command > foo.log Redirecting STDERR to a file is also easy: command 2> foo.log Redirecting both STDOUT and STDERR to a file is also fairly straightforward: command &#038;> foo.log But what if we want to append to the log rather than truncating it each time we write? This [...]]]></description>
			<content:encoded><![CDATA[<p>Redirecting STDOUT to a file is easy:</p>
<p><code>command > foo.log</code></p>
<p>Redirecting STDERR to a file is also easy:</p>
<p><code>command 2> foo.log</code></p>
<p>Redirecting both STDOUT and STDERR to a file is also fairly straightforward:</p>
<p><code>command &#038;> foo.log</code></p>
<p>But what if we want to append to the log rather than truncating it each time we write?   This is done for STDOUT by using the >> operator, and for STDERR by using 2>>.   Unfortunately &#038;>> does not exist, so how do we append both STDOUT and STDERR?</p>
<p>The solution is to redirect STDERR to STDOUT, and then redirect STDOUT to a file using the append operator:</p>
<p><code><strong>command 1>> foo.txt 2>&#038;1</strong></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2010/06/redirect-and-append-stdout-and-stderr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.10 Karmic Koala: Temperature above threshold, cpu clock throttled</title>
		<link>http://www.4pmp.com/2009/11/ubuntu-9-10-karmic-koala-temperature-above-threshold-cpu-clock-throttled/</link>
		<comments>http://www.4pmp.com/2009/11/ubuntu-9-10-karmic-koala-temperature-above-threshold-cpu-clock-throttled/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 11:31:51 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[9.10]]></category>
		<category><![CDATA[above]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[karmic koala]]></category>
		<category><![CDATA[kern.log]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[syslog]]></category>
		<category><![CDATA[temperature]]></category>
		<category><![CDATA[threshold]]></category>
		<category><![CDATA[throttled]]></category>
		<category><![CDATA[throttling]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=198</guid>
		<description><![CDATA[I recently upgraded my Ubuntu install to the latest Karmic Koala, and to be honest I&#8217;ve not been totally impressed.   A range of little bugs that had been fixed before seem to have reappeared &#8211; just little things such as problems with icons in Gnome panel, nothing I couldn&#8217;t live with. However, yesterday I got [...]]]></description>
			<content:encoded><![CDATA[<p>I recently upgraded my Ubuntu install to the latest Karmic Koala, and to be honest I&#8217;ve not been totally impressed.   A range of little bugs that had been fixed before seem to have reappeared &#8211; just little things such as problems with icons in Gnome panel, nothing I couldn&#8217;t live with.</p>
<p>However, yesterday I got a message saying that there was less than 2GB left on my hard drive.   The last time I checked I had over 20GB free, so where did it all go?   After a bit of investigating I found two giant 10GB kernel log files /var/log/kern.log.</p>
<p>It seemed that the computer was constantly logging the same messages:</p>
<p><code><strong>CPU0: Temperature above threshold, cpu clock throttled (total events = 208[ 8973.550089] CPU0: Temperature/speed normal</strong></code></p>
<p><code><strong>CPU0: Temperat cpu clock throttled (total events = 2080190)</strong></code></p>
<p>I had a look on Google and it turns out that it is a bug with the new Karmic Koala update:</p>
<p><a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/453444">https://bugs.launchpad.net/ubuntu/+source/linux/+bug/453444</a></p>
<p>So far there&#8217;s no patch for it, so the best solution I came up with was just to turn off the logging.</p>
<p><strong>Step 1:</strong><br />
Look in /etc/rsyslog.conf and it will either have the configuration for system logging, or in the case of my machine it points to include all files in /etc/rsyslog.d/   In my case there was only one file in here so it made things simpler.</p>
<p><strong>Step 2:</strong><br />
Open the configuration file in an editor and find the line which specifies kernel logging and comment it, something like:</p>
<p><code>#kern.*                         -/var/log/kern.log</code></p>
<p><strong>Step 3:</strong><br />
Now restart the system log daemon:   sudo restart rsyslog</p>
<p>It is the logging which hogs the processor so by turning it off the problem is at least not noticeable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2009/11/ubuntu-9-10-karmic-koala-temperature-above-threshold-cpu-clock-throttled/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Logging and monitoring server load</title>
		<link>http://www.4pmp.com/2009/09/logging-and-monitoring-server-load/</link>
		<comments>http://www.4pmp.com/2009/09/logging-and-monitoring-server-load/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 19:42:35 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cvs]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[spreadsheet]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=46</guid>
		<description><![CDATA[We decided it would be a good idea to be able to periodically log server load so we can identify potential problems So I wrote a little script that outputs the current server load along with a timestamp in CSV format which can easily be called via CRON and send the output to a log [...]]]></description>
			<content:encoded><![CDATA[<p>We decided it would be a good idea to be able to periodically log server load so we can identify potential problems   So I wrote a little script that outputs the current server load along with a timestamp in CSV format which can easily be called via CRON and send the output to a log file which can then be imported into a spreadsheet.</p>
<p><a href='http://www.4pmp.com/wp-content/uploads/2009/09/load.c'>getload.c</a></p>
<p>Just compile it and run it.   The output should be something like:</p>
<p><code>"1251834476","0.21"</code></p>
<p><em>It turns out that Nagios logs server load anyway, but not quite as accurately as this.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2009/09/logging-and-monitoring-server-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rsync &#8211; non recursive copying</title>
		<link>http://www.4pmp.com/2009/08/rsync-non-recursive-copying/</link>
		<comments>http://www.4pmp.com/2009/08/rsync-non-recursive-copying/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 20:41:24 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[copying]]></category>
		<category><![CDATA[non-recursive]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://blog.4pmp.com/?p=28</guid>
		<description><![CDATA[I was looking for a way to get rsync to copy all the files in a particular directory and not recurse into the sub-directories.   Unfortunately I couldn&#8217;t find an appropriate parameter and a quick search on Google turned up nothing (apart from a lot of other people asking the same question!) So as a last [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a way to get rsync to copy all the files in a particular directory and not recurse into the sub-directories.   Unfortunately I couldn&#8217;t find an appropriate parameter and a quick search on Google turned up nothing (apart from a lot of other people asking the same question!)</p>
<p>So as a last resort I decided to use my brain, and I came up with a simple solution that works.   It&#8217;s of the form:</p>
<p><code>rsync -avc --exclude "*/" ./source/* ./destination/<br />
</code></p>
<p>The above will copy all the files from the directory called &#8220;source&#8221; into the directory &#8220;destination&#8221; and will not recurse into any subdirectories of &#8220;source&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2009/08/rsync-non-recursive-copying/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

