<?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>Japh &#187; Networking</title>
	<atom:link href="http://japh.com.au/category/networking/feed/" rel="self" type="application/rss+xml" />
	<link>http://japh.com.au</link>
	<description>Web developer, technologist, innovator. I love the internet.</description>
	<lastBuildDate>Tue, 13 Jul 2010 10:48:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tracking memory usage</title>
		<link>http://japh.com.au/general/tracking-memory-usage/</link>
		<comments>http://japh.com.au/general/tracking-memory-usage/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 12:35:51 +0000</pubDate>
		<dc:creator>Japh</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General Chatter]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://japheththomson.com/?p=67</guid>
		<description><![CDATA[Recently I received a warning from my host that I was WAY over my memory limit.  I had some long running processes going, and a few cron scripts that altogether were using about 220mb out of my 120mb of allowed memory usage&#8230;  oops!
Anyway, there&#8217;s currently no way from my control panel to see [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Recently I received a warning from my host that I was WAY over my memory limit.  I had some long running processes going, and a few cron scripts that altogether were using about 220mb out of my 120mb of allowed memory usage&#8230;  oops!</p>
<p>Anyway, there&#8217;s currently no way from my control panel to see how memory I&#8217;m currently using, I have to run a command from a terminal, and certainly no way to tell usage over time.  So, after looking at a thread my hosting provider pointed me to, I decided to have a play with the Google Charts API!<br />
<span id="more-67"></span><br />
This is a pretty rudimentary solution, but it&#8217;s working so far for me.</p>
<p><strong>1. A very simple bash script</strong></p>

<div class="wp_codebox"><table><tr id="p675"><td class="code" id="p67code5"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-u</span> username <span style="color: #660033;">-o</span> pid,rss,<span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-e</span> mpm <span style="color: #660033;">-v</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{sum+=$2} END {print &quot;,&quot;, sum}'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>webroot<span style="color: #000000; font-weight: bold;">/</span>mem<span style="color: #000000; font-weight: bold;">/</span>memdata.csv</pre></td></tr></table></div>

<p>The script basically just outputs the current memory usage at the time of running and appends it to a CSV file.</p>
<p><strong>2. Add the script to the crontab</strong></p>
<p>By running the following command (or one similar), I edit my crontab:</p>

<div class="wp_codebox"><table><tr id="p676"><td class="code" id="p67code6"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span></pre></td></tr></table></div>

<p>I then insert this line:</p>

<div class="wp_codebox"><table><tr id="p677"><td class="code" id="p67code7"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>full<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>memlogger</pre></td></tr></table></div>

<p>So now that bash script will be run every hour, on the hour.</p>
<p><strong>3. Writing a PHP script to display a Google Chart</strong></p>

<div class="wp_codebox"><table><tr id="p678"><td class="code" id="p67code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Settings</span>
<span style="color: #000088;">$max_mem</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Your memory limit, in MB</span>
<span style="color: #000088;">$data_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'memdata.csv'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$chart_width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">550</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$chart_height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Memory Usage<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>Memory Usage<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$md</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$md</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\s+|\n)/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$md</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$md</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$md</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/array_shift"><span style="color: #990000;">array_shift</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$md</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$md</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$max</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_mem</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$max</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://chart.apis.google.com/chart?cht=lc&amp;chd=t:&lt;?php echo implode(',', <span style="color: #006699; font-weight: bold;">$md</span>); ?&gt;&amp;chs=&lt;?php echo <span style="color: #006699; font-weight: bold;">$chart_width</span>; ?&gt;x&lt;?php echo <span style="color: #006699; font-weight: bold;">$chart_height</span>; ?&gt;&amp;chxt=y,r&amp;chxr=0,&lt;?php echo <span style="color: #006699; font-weight: bold;">$min</span>; ?&gt;,&lt;?php echo <span style="color: #006699; font-weight: bold;">$max</span>; ?&gt;|1,&lt;?php echo <span style="color: #006699; font-weight: bold;">$min</span>; ?&gt;,&lt;?php echo <span style="color: #006699; font-weight: bold;">$max</span>; ?&gt;&amp;chds=&lt;?php echo <span style="color: #006699; font-weight: bold;">$min</span>; ?&gt;,&lt;?php echo <span style="color: #006699; font-weight: bold;">$max</span>; ?&gt;&amp;chm=r,FF0000,0,&lt;?php echo <span style="color: #006699; font-weight: bold;">$base</span>; ?&gt;,&lt;?php echo <span style="color: #006699; font-weight: bold;">$base</span>+0.005; ?&gt;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>This code basically just imports the data into an array, and then works a few things out for proper axis labelling, and away it goes!  It&#8217;s pretty quick and dirty, and could probably have been done nicer&#8230;  maybe I&#8217;ll come back and fix it up some time.</p>
<p>It also uses your memory limit amount to show a red line on the graph if you go over  <img src='http://japh.com.au/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Here&#8217;s the chart using some sample data:<br />
<img src="http://japh.com.au/wp-content/uploads/2009/02/memory-usage-chart-300x245.jpg" alt="Memory Usage Chart" title="Memory Usage Chart" width="300" height="245" class="alignnone size-medium wp-image-75" /></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://japh.com.au/general/tracking-memory-usage/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DIY Dynamic DNS</title>
		<link>http://japh.com.au/networking/diy-dynamic-dns/</link>
		<comments>http://japh.com.au/networking/diy-dynamic-dns/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 11:17:05 +0000</pubDate>
		<dc:creator>Japh</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://japheththomson.com/?p=10</guid>
		<description><![CDATA[I&#8217;ve setup my home network with a domain and wanted to be able to access my home server, from my office, on a subdomain.
However, as is probably the case for most of you, I have a dynamic IP address assigned to my router when it connects to the Internet through my ISP.  So I [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve setup my home network with a domain and wanted to be able to access my home server, from my office, on a subdomain.</p>
<p>However, as is probably the case for most of you, I have a dynamic IP address assigned to my router when it connects to the Internet through my ISP.  So I decided I&#8217;d have to setup my own dynamic DNS process!</p>
<p>First things first, it was necessary to create the subdomain I wanted and point it to my home router&#8217;s external IP address, and also to change the configuration on my router to forward all traffic on port 80 to my home server&#8217;s internal IP address.<br />
<span id="more-10"></span><br />
Next I needed a small script, PHP in this case, on my web server that simply outputs a tiny bit of XML with the current IP address of the visitor.</p>

<div class="wp_codebox"><table><tr id="p1011"><td class="code" id="p10code11"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'; ?&amp;gt;
&lt;!--[CDATA[&lt;?php echo $_SERVER['</span>REMOTE_ADDR<span style="color: #0000ff;">']--&gt;]]&amp;gt;</span></pre></td></tr></table></div>

<p>Then I wrote a small Python script that retrieves the IP address from the PHP script, and calls <a title="WebFaction - Hosting for an agile web" href="http://www.webfaction.com/services/hosting?affiliate=japheth" target="_blank">WebFaction</a>&#8217;s server API to update the DNS record.  This script runs on a crontab every hour, so if my IP address changes, I only have to wait an hour at most for an update.</p>

<div class="wp_codebox"><table><tr id="p1012"><td class="code" id="p10code12"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">dom</span> <span style="color: #ff7700;font-weight:bold;">import</span> minidom
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">xmlrpclib</span>
dyndomain = <span style="color: #483d8b;">'homeserver.example.com'</span>
ip_url = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.example.com/ip.php'</span><span style="color: black;">&#41;</span>
ip_dom = minidom.<span style="color: black;">parse</span><span style="color: black;">&#40;</span>ip_url<span style="color: black;">&#41;</span>
ip_string = ip_dom.<span style="color: black;">toxml</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
ip_address = ip_dom.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;ip&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">childNodes</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">data</span>
<span style="color: #ff7700;font-weight:bold;">print</span> ip_address
server = <span style="color: #dc143c;">xmlrpclib</span>.<span style="color: black;">ServerProxy</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://api.webfaction.com/'</span><span style="color: black;">&#41;</span>
session_id, account = server.<span style="color: black;">login</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'username'</span>, <span style="color: #483d8b;">'password'</span><span style="color: black;">&#41;</span>
server.<span style="color: black;">delete_dns_override</span><span style="color: black;">&#40;</span>session_id, dyndomain<span style="color: black;">&#41;</span>
server.<span style="color: black;">create_dns_override</span><span style="color: black;">&#40;</span>session_id, dyndomain, ip_address, <span style="color: #483d8b;">''</span>, <span style="color: #483d8b;">''</span>, <span style="color: #483d8b;">''</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Next I may add logging, so I can see when my IP address changes, but that&#8217;s optional really.</p>
<p><strong>Note:</strong> Also, if someone can recommend a really good code-highlighter plugin for WordPress, I&#8217;d be <em>very</em> grateful!</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://japh.com.au/networking/diy-dynamic-dns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fun with wild-card domain names</title>
		<link>http://japh.com.au/php/fun-with-wild-card-domain-names/</link>
		<comments>http://japh.com.au/php/fun-with-wild-card-domain-names/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 00:25:59 +0000</pubDate>
		<dc:creator>Japh</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DNS]]></category>

		<guid isPermaLink="false">http://japheththomson.com/2008/09/16/fun-with-wild-card-domain-names/</guid>
		<description><![CDATA[After seeing quite a few websites with dynamic content based on the domain name, I wanted to give it a try to see how difficult it was to achieve.
Here&#8217;s what I came up with: DueABootin.com
As it turns out, it wasn&#8217;t very difficult at all!  (Especially being hosted through WebFaction, they make it even easier!)

First, I [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>After seeing quite a few websites with dynamic content based on the domain name, I wanted to give it a try to see how difficult it was to achieve.</p>
<p>Here&#8217;s what I came up with: <a title="DueABootin.com" href="http://reader.of.my.blog.dueabootin.com" target="_blank">DueABootin.com</a></p>
<p>As it turns out, it wasn&#8217;t very difficult at all!  (Especially being hosted through <a title="WebFaction - Hosting for an agile web" href="http://www.webfaction.com/services/hosting?affiliate=japheth" target="_blank">WebFaction</a>, they make it even easier!)<br />
<span id="more-7"></span><br />
First, I added the domain to my control panel, an added a subdomain of &#8220;*&#8221;, as you can see in the screenshot below.</p>
<p><img title="WebFaction Control Panel - DueABootin.com" src="http://japheththomson.com/img/wf_cp_dueabootin.png" alt="WebFaction Control Panel - DueABootin.com" width="371" height="202" /></p>
<p>And that&#8217;s really the hardest part, because PHP provides a nice little pre-defined variable called $_SERVER['HTTP_HOST'] which then gives us &#8220;example.dueabootin.com&#8221;, which we can pull apart and do with what we like.</p>
<p><strong>Update: I&#8217;ve had a bit of a look into how difficult it might be to achieve the same results with cPanel, and it&#8217;s not much more difficult.</strong></p>
<p>Create a new sub-domain called &#8220;*&#8221; which does not re-direct, just points to public_html/, and you should be fine.  If that alone doesn&#8217;t work, then you may need to add an A record to your DNS zone file something like:</p>
<p>*.example.com.  14400  IN  A  192.168.1.101</p>
<p>(don&#8217;t forget the trailing &#8220;.&#8221; after &#8220;.com&#8221;)</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://japh.com.au/php/fun-with-wild-card-domain-names/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
