<?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>Dirty Trolls</title>
	<atom:link href="http://www.dirtytrolls.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dirtytrolls.com</link>
	<description>...random crap from a keyboard</description>
	<lastBuildDate>Tue, 09 Mar 2010 23:08:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Misc subversion commands and information vol 1</title>
		<link>http://www.dirtytrolls.com/2010/03/05/misc-subversion-commands-and-information-vol-1/</link>
		<comments>http://www.dirtytrolls.com/2010/03/05/misc-subversion-commands-and-information-vol-1/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:31:10 +0000</pubDate>
		<dc:creator>Terry Valladon</dc:creator>
				<category><![CDATA[subversion]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[peeks]]></category>
		<category><![CDATA[pokes]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.dirtytrolls.com/?p=283</guid>
		<description><![CDATA[Keep in mind this is based on MY development and deployment environment, in your environment things will be a bit different.
{esc} = Press escape key.
{everything else} = Needs changed for your project or case.
Do not type # hash or anything after it.
Where it says &#8220;root&#62; &#8221; you may also assume &#8220;admin_user&#62; sudo &#8221; if you [...]]]></description>
			<content:encoded><![CDATA[<p>Keep in mind this is based on MY development and deployment environment, in your environment things will be a bit different.<br />
{esc} = Press escape key.<br />
{everything else} = Needs changed for your project or case.<br />
Do not type # hash or anything after it.</p>
<p>Where it says &#8220;root&gt; &#8221; you may also assume &#8220;admin_user&gt; sudo &#8221; if you like to use protection.</p>
<p>Create new svn user:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> htpassd -m /etc/apache2/dav_svn.passwd {username}
	<span style="color: #ff9900;"># will ask for password twice</span></pre>
<p></div></div></p>
<p>Create svn project:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> cd /path/to/svn/repo/root
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> svnadmin create {project name}
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> chown -R www-data: ./{project name}</pre>
<p></div></div></p>
<p>First import for project:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> mkdir svn_{project}_core
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> cd svn_{project}_core
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> mkdir trunk
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> mkdir tags
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> mkdir branches
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> cd trunk
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> cp -r /path/to/existing/files/ ./
	<span style="color: #ff9900;"># repeat for . files in root direcotry (.htaccess for example)</span>
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> cd ..
	<span style="color: #ffff00;">user</span><span style="color: #ff6600;">&gt;</span> svn import -m 'Initial Import' ./ http://hostname.or.ip/svn/project
	<span style="color: #ff9900;"># system will ask for svn username and password</span></pre>
<p></div></div></p>
<p>Checkout project to web location:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> su - www-data
	<span style="color: #ffff00;">www-data</span><span style="color: #ff6600;">&gt;</span> cd /var/www/sites/{project}/
	<span style="color: #ff9900;"># directory must be blank, delete contents and . files if not</span>
	<span style="color: #ff9900;"># directory must be owned by www-data user</span>
	<span style="color: #ffff00;">www-data</span><span style="color: #ff6600;">&gt;</span> svn co http://hostname.or.ip/svn/{project} ./</pre>
<p></div></div></p>
<p>Create auto publish post commit hook:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> cd /path/to/svn/repo/{project}/hooks
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> ls post-commit

  <span style="color: #ff9900;"># if file does not exist:</span>
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> touch post-commit
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> vim post-commit
		i
		#!/bin/sh
		/usr/bin/svn update /var/www/sites/{project} --username www-data --password ************
		{esc}
		:wq
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> chown www-data: post-commit
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> chmod +x post-commit

  <span style="color: #ff9900;"># if file exists:</span>
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> vim post-commit
		:9999999
		o
		/usr/bin/svn update /var/www/sites/{project} --username www-data --password ************
		{esc}
		:wq</pre>
<p></div></div></p>
<p>Test post-commit hook:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> cd /path/to/svn/repo/{project}/hooks
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> su - www-data
	<span style="color: #ffff00;">www-data</span><span style="color: #ff6600;">&gt;</span> env - ./post-commit
	<span style="color: #ff9900;"># errors will be reported</span></pre>
<p></div></div></p>
<p>Add project to websvn:<br />
<div class='shell'><div></p>
<pre>	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> cd /path/to/websvn/web/root/include/
	<span style="color: #ffff00;">root</span><span style="color: #ff6600;">&gt;</span> vim config.php
		/Local
		o
		$config-&gt;addRepository('{project name}', 'file:///path/to/svn/repo/{project}');
		{esc}
		:wq
	<span style="color: #ff9900;"># Load websvn in browser and see project.</span></pre>
<p></div></div></p>
<p>Enjoy, I will post &#8216;Misc subversion commands and information vol 2&#8242;  in a few weeks.</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Terry Valladon (<span style='color: #FF0000'>T</span><span style='color: #F72F00'>h</span><span style='color: #E16100'>e</span><span style='color: #BE9300'>&nbsp;</span><span style='color: #93BE00'>D</span><span style='color: #61E100'>i</span><span style='color: #2FF700'>r</span><span style='color: #00FF00'>t</span><span style='color: #00F72F'>y</span><span style='color: #00E161'>&nbsp;</span><span style='color: #00BE93'>T</span><span style='color: #0093BE'>r</span><span style='color: #0061E1'>o</span><span style='color: #002FF7'>l</span><span style='color: #0000FF'>l</span>)
<p>Edits:</p>
<p>Fixed name of password file (was missing .passwd)</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/linux' rel='tag' target='_self'>linux</a>, <a class='technorati-link' href='http://technorati.com/tag/peeks' rel='tag' target='_self'>peeks</a>, <a class='technorati-link' href='http://technorati.com/tag/pokes' rel='tag' target='_self'>pokes</a>, <a class='technorati-link' href='http://technorati.com/tag/shell' rel='tag' target='_self'>shell</a>, <a class='technorati-link' href='http://technorati.com/tag/subversion' rel='tag' target='_self'>subversion</a>, <a class='technorati-link' href='http://technorati.com/tag/svn' rel='tag' target='_self'>svn</a>, <a class='technorati-link' href='http://technorati.com/tag/tips' rel='tag' target='_self'>tips</a>, <a class='technorati-link' href='http://technorati.com/tag/tricks' rel='tag' target='_self'>tricks</a>, <a class='technorati-link' href='http://technorati.com/tag/ubuntu' rel='tag' target='_self'>ubuntu</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.dirtytrolls.com/2010/03/05/misc-subversion-commands-and-information-vol-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A very special day&#8230;</title>
		<link>http://www.dirtytrolls.com/2009/03/18/a-very-special-day/</link>
		<comments>http://www.dirtytrolls.com/2009/03/18/a-very-special-day/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 14:55:17 +0000</pubDate>
		<dc:creator>Terry Valladon</dc:creator>
				<category><![CDATA[Site News]]></category>

		<guid isPermaLink="false">http://www.dirtytrolls.com/?p=239</guid>
		<description><![CDATA[Daily system check:
Yay to me! Another year older and wiser.
May you all have a happy day as well  
Till next time, code sexy.




]]></description>
			<content:encoded><![CDATA[<p>Daily system check:</p>
<div class='shell'><div><span style="color: #ffff00;">root@terryvalladon</span><span style="color: #ffffff;">&gt;</span> uptime<br />
08:12:22 up 35 years,  0:00,  2 siblings, 3 child processes,  1 user, load average: 1.00, 1.00, 1.00<br />
<span style="color: #ffff00;">root@terryvalladon</span><span style="color: #ffffff;">&gt;</span> dmesg<br />
<span style="color: #FF0000">H</span><span style="color: #FA2200">A</span><span style="color: #EE4600">P</span><span style="color: #DB6C00">P</span><span style="color: #C19000">Y</span><span style="color: #A1B100"> </span><span style="color: #7ECE00">B</span><span style="color: #59E500">I</span><span style="color: #34F500">R</span><span style="color: #10FD00">T</span><span style="color: #00FD10">H</span><span style="color: #00F534">D</span><span style="color: #00E559">A</span><span style="color: #00CE7E">Y</span></div></div><br />
Yay to me! Another year older and wiser.</p>
<p>May you all have a happy day as well <img src='http://www.dirtytrolls.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Till next time, code sexy.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Terry Valladon (<span style='color: #FF0000'>T</span><span style='color: #F72F00'>h</span><span style='color: #E16100'>e</span><span style='color: #BE9300'>&nbsp;</span><span style='color: #93BE00'>D</span><span style='color: #61E100'>i</span><span style='color: #2FF700'>r</span><span style='color: #00FF00'>t</span><span style='color: #00F72F'>y</span><span style='color: #00E161'>&nbsp;</span><span style='color: #00BE93'>T</span><span style='color: #0093BE'>r</span><span style='color: #0061E1'>o</span><span style='color: #002FF7'>l</span><span style='color: #0000FF'>l</span>)

<!-- start wp-tags-to-technorati 1.01 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.dirtytrolls.com/2009/03/18/a-very-special-day/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remote debugging with UDP sockets part 2</title>
		<link>http://www.dirtytrolls.com/2009/03/15/remote-debugging-with-udp-sockets-part-2/</link>
		<comments>http://www.dirtytrolls.com/2009/03/15/remote-debugging-with-udp-sockets-part-2/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 22:55:30 +0000</pubDate>
		<dc:creator>Terry Valladon</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[PHP Magic]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://www.dirtytrolls.com/?p=211</guid>
		<description><![CDATA[With our last article on debugging PHP with UDP sockets we created a new class able to send debugging information from PHP to a remote netcat client. The limit of the code was that it could only send strings and not arrays or an object. Today we will modify the code to send arrays to [...]]]></description>
			<content:encoded><![CDATA[<a class='entry_img' href='/tags/code'><img src='/assets/post_photos/code.jpg'></a>
<p>With our last article on <a href="/2009/02/11/remote-php-debugging-with-udp-sockets-part-1/">debugging PHP with UDP sockets </a>we created a new class able to send debugging information from PHP to a remote netcat client. The limit of the code was that it could only send strings and not arrays or an object. Today we will modify the code to send arrays to our remote listening client.</p>
<p>First, I will show you what happens if we try to send an array using the UDPDEBUG class that we currently have. To do this we will create a very simple array and then attempt to send it.</p>
<div class='code' class='code'>&nbsp;php&nbsp;(udptest2.phps)&nbsp;<a href='/assets/udptest2.phps'>download</a><pre lang='php'>&lt;?
	$ThisWeek = array(1 =&gt; 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',  'Saturday', 'Sunday');

	require_once("UDPDEBUG_CLASS.php");
	$UDPDEBUG = new UDPDEBUG("127.0.0.1", 4545);
	$UDPDEBUG-&gt;SEND($ThisWeek, 'LOW', TRUE);
?&gt;

    </pre></div>
<p>This test code results in no useful information other then the fact we are dealing with an array.</p>
<a href='/assets/udp_test2_output.jpg'><img src='/assets/udp_test2_output.jpg'></a>
<p><span id="more-211"></span>What we really want is to output the array in much the way print_f does; nice and formatted for easy viewing. To do this we are going to modify our <em>send</em> function from our UDP class and add in some array checking.</p>
<p>Here is our <em>send</em> function before and after the edit we are going to make:</p>
<div class='code' class='code'>&nbsp;php&nbsp;(udpdebug_send_function_before.phps)&nbsp;<a href='/assets/udpdebug_send_function_before.phps'>download</a><pre lang='php'>                function SEND($STRING, $LEVEL = 1, $VERBOSE = FALSE)
                {
                        $LEVEL = $this-&gt;LEVEL[$LEVEL];
                        if($VERBOSE == TRUE){
                                $OUTPUT = sprintf("[%s]:%s:%s%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG['CYAN'].$this-&gt;PORT,$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].str_pad($this-&gt;LEVEL_WORDS[$LEVEL], 9),$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL'], $STRING);
                        }else{
                                $OUTPUT = sprintf("%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].$STRING.$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL']);
                        }
                        $this-&gt;UPD_OBJECT = fsockopen("udp://" . $this-&gt;IP_ADDRESS, $this-&gt;PORT, $this-&gt;ERR_NO, $this-&gt;ERR_STR);
                        if (!$this-&gt;UPD_OBJECT) {
                                echo "ERROR IN UDP SYSTEM: $this-&gt;ERR_NO - $this-&gt;ERR_STR&lt;br /&gt;\n";
                                return 0;
                        }
                        fwrite($this-&gt;UPD_OBJECT, $OUTPUT);
                        fclose($this-&gt;UPD_OBJECT);
                }

    </pre></div> <div class='code' class='code'>&nbsp;php&nbsp;(udpdebug_send_function_after.phps)&nbsp;<a href='/assets/udpdebug_send_function_after.phps'>download</a><pre lang='php'>                function SEND($STRING, $LEVEL = 1, $VERBOSE = FALSE)
                {
                        $LEVEL = $this-&gt;LEVEL[$LEVEL];
			if(is_array($STRING))
			{
				$STRING = print_r($STRING, true);
			}
                        if($VERBOSE == TRUE){
                                $OUTPUT = sprintf("[%s]:%s:%s%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG['CYAN'].$this-&gt;PORT,$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].str_pad($this-&gt;LEVEL_WORDS[$LEVEL], 9),$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL'], $STRING);
                        }else{
                                $OUTPUT = sprintf("%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].$STRING.$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL']);
                        }
                        $this-&gt;UPD_OBJECT = fsockopen("udp://" . $this-&gt;IP_ADDRESS, $this-&gt;PORT, $this-&gt;ERR_NO, $this-&gt;ERR_STR);
                        if (!$this-&gt;UPD_OBJECT) {
                                echo "ERROR IN UDP SYSTEM: $this-&gt;ERR_NO - $this-&gt;ERR_STR&lt;br /&gt;\n";
                                return 0;
                        }
                        fwrite($this-&gt;UPD_OBJECT, $OUTPUT);
                        fclose($this-&gt;UPD_OBJECT);
                }


    </pre></div>
<p>As you can see, what we added was a simple if clause that will redefine our $STRING as $STRING = print_r($STRING, true) if our passed item is an array.</p>
<div class='article-ad'>
<script type='text/javascript'><!--
google_ad_client = 'pub-0797652291746169';
/* 468x60, created 2/23/08 */
google_ad_slot = '8955222875';
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
</div>

<p>With this simple modification our test code above now produces some useful output when the passed object is an array.</p>
<a href='/assets/udp_test2_output_fixed.jpg'><img src='/assets/udp_test2_output_fixed.jpg'></a>
<p>This modification will work even with very large and complicated multidimensional arrays.</p>
<p>Till next time, code sexy.<br />
&#8211;Terry Valladon</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/class' rel='tag' target='_self'>class</a>, <a class='technorati-link' href='http://technorati.com/tag/code' rel='tag' target='_self'>code</a>, <a class='technorati-link' href='http://technorati.com/tag/debugging' rel='tag' target='_self'>debugging</a>, <a class='technorati-link' href='http://technorati.com/tag/php' rel='tag' target='_self'>php</a>, <a class='technorati-link' href='http://technorati.com/tag/sockets' rel='tag' target='_self'>sockets</a>, <a class='technorati-link' href='http://technorati.com/tag/tutorial' rel='tag' target='_self'>tutorial</a>, <a class='technorati-link' href='http://technorati.com/tag/udp' rel='tag' target='_self'>udp</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.dirtytrolls.com/2009/03/15/remote-debugging-with-udp-sockets-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote debugging with UDP sockets part 1</title>
		<link>http://www.dirtytrolls.com/2009/02/11/remote-php-debugging-with-udp-sockets-part-1/</link>
		<comments>http://www.dirtytrolls.com/2009/02/11/remote-php-debugging-with-udp-sockets-part-1/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:13:32 +0000</pubDate>
		<dc:creator>Terry Valladon</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[PHP Magic]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://www.dirtytrolls.com/?p=105</guid>
		<description><![CDATA[The nature of Internet applications creates an issue with debugging. For example, how do you debug an application that may be getting hundreds or even thousands of hits every minute? How do you debug this application without sending sensitive data to the user in the form of comments or debug statements that are &#8220;hidden&#8221; for [...]]]></description>
			<content:encoded><![CDATA[<a class='entry_img' href='/tags/code'><img src='/assets/post_photos/code.jpg'></a>
<p>The nature of Internet applications creates an issue with debugging. For example, how do you debug an application that may be getting hundreds or even thousands of hits every minute? How do you debug this application without sending sensitive data to the user in the form of comments or debug statements that are &#8220;hidden&#8221; for only as long as nobody is looking for them? What do you do when you are unable to trigger an error but your user base is, though they lack the knowledge to be of much assistance other then &#8220;I borked it!&#8221;?</p>
<p>There are several new contenders on the debugging scene for <a href='http://www.php.net'>PHP</a> code, the most popular of which is <a href='http://www.firephp.org/'>FirePHP</a> and their unholy union with <a href='http://http://getfirebug.com/'>FireBug</a>. These two are great tools for debugging an Internet application but they both suffer from one fatal flaw in my eyes: the ability to view debugging information from anonymous Internet users.</p>
<p>Sure, it is a great feature to be able to hit a site and have debugging information pop up in a panel in my browser but how does that help me when dealing with users that I do not personally know? It doesn&#8217;t&#8230; Dumping data to a .log file offers several problems in and of itself, the largest of which is the rate at which said log file can reach an unwieldy size.</p>
<p>Another flaw in <a href='http://www.firephp.org/'>FirePHP</a> is that sometimes you just want it short, sweet and not sent to the client. For years I have gone with a tried and true method of remote debugging which allows for me to view dumped data on a remote server. Yes, a REMOTE server&#8230; as in 3000 miles away and not in my browser.</p>
<p><span id="more-105"></span></p>
<p>UDP is a stateless Internet protocol which allows for no handshaking or error checking, this creates an almost &#8220;fire and forget&#8221; method of sending packets to a remote system. UDP is perfect when you do not want to stop things to make sure the other side gets the information and you don&#8217;t really care if there is even someone at the other end listening.</p>
<p>USAGE:</p>
<div class='code'>&nbsp;php snippet<pre lang='php'>require_once("UDPDEBUG_CLASS.php");
$UDPDEBUG = new UDPDEBUG("127.0.0.1", 4545);
$UDPDEBUG-&gt;SEND("This is a simple test", 'LOW', TRUE);
    </pre></div>
<p>Line:</p>
<p>1. Include the debugging class</p>
<p>2. Create a new object and tell it we are using the ip address 127.0.0.1 and port 4545</p>
<p>3. Send our data debug statement to the server with a low priority and display the PORT and LEVEL.</p>
<p>Three lines is all it takes to send the data off and we can easily replace &#8220;This is a simple test&#8221; with $our_value.</p>
<div class='article-ad'>
<script type='text/javascript'><!--
google_ad_client = 'pub-0797652291746169';
/* 468x60, created 2/23/08 */
google_ad_slot = '8955222875';
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
</div>

<p>Reading this data can be done using several different tools but the one I will focus on here is <a href='http://netcat.sourceforge.net/'>Netcat</a>, which is a network diagnostic tool.</p>
<p>From a command console (or windows CMD prompt with access to the NC binary) type:</p>
<p>nc -u -l -p 4545</p>
<p>This will start <a href='http://netcat.sourceforge.net/'>Netcat</a> listening (-l) on UDP (-u) port (-p) 4545, now when we hit our udpdebug enabled page <a href='http://netcat.sourceforge.net/'>Netcat</a> will spit out the information we wish to see. For this example I am using this test file:</p>
<div class='code' class='code'>&nbsp;php&nbsp;(udptest.phps)&nbsp;<a href='/assets/udptest.phps'>download</a><pre lang='php'>&lt;?
require_once("UDPDEBUG_CLASS.php");
$UDPDEBUG = new UDPDEBUG("127.0.0.1", 4545);
$UDPDEBUG-&gt;SEND("This is a simple test", 'LOW', TRUE);
$UDPDEBUG-&gt;SEND("This is a simple test", 'MEDIUM', TRUE);
$UDPDEBUG-&gt;SEND("This is a simple test", 'HIGH', TRUE);
$UDPDEBUG-&gt;SEND("This is a simple test", 'LOW', FALSE);
$UDPDEBUG-&gt;SEND("This is a simple test", 'MEDIUM', FALSE);
$UDPDEBUG-&gt;SEND("This is a simple test", 'HIGH', FALSE);
?&gt;

    </pre></div>
<p>Which produces the following output if everything works right:</p>
<a href='/assets/udp_test_output.jpg'><img src='/assets/udp_test_output.jpg'></a>
<p>The reason that UDP will send the port and level if requested is because I often assign a unique port number to each application I am working on. Meaning that I have created a simple application that listens full time on a list of ports I have specified. This way I can check and see if all of the sudden my_nifty_webapp.com is throwing a database error because its port number is 12127.</p>
<div class='code' class='code'>&nbsp;php&nbsp;(UDPDEBUG_CLASS.phps)&nbsp;<a href='/assets/UDPDEBUG_CLASS.phps'>download</a><pre lang='php'>&lt;?php
/**********************************************************************
*	Author:	Terry Valladon (terry@terryvalladon.com)
*	Web...:	http://www.terryvalladon.com
*	Name..:	UDBDebug Class
*	Desc..:	This class is used to send debug messages as a datagram packet to a UDP port
*
*	Notes.:	&lt;IP ADDRESS&gt;	= The IP address you want the packet sent to
*		&lt;PORT&gt;		= The port you want the packet sent to
*		&lt;LEVEL&gt;		= LOW, MEDIUM, HIGH
*		&lt;VERBOSE&gt;	= TRUE, FALSE - Display information like LEVEL and PORT
*
*	Usage.:	require_once("UDPDEBUG_CLASS.php");            
*		$UDPDEBUG = new UDPDEBUG(&lt;IP ADDRESS&gt;, &lt;PORT&gt;);
*		$UDPDEBUG-&gt;SEND($MESSAGE, &lt;LEVEL&gt;, &lt;VERBOSE&gt;);
*
*/

	class UDPDEBUG {
		public $IP_ADDRESS;
		public $PORT;
		public $UDP_OBJECT;
		public $ERR_NO;
		public $ERR_STR;
		public $ESC_CHR;
		public $LEVEL = array('LOW'=&gt;0,'MEDIUM'=&gt;1,'HIGH'=&gt;2);
		public $LEVEL_WORDS = array(0=&gt;'LOW',1=&gt;'MEDIUM',2=&gt;'HIGH');
		public $LEVEL_COLORS = array(0=&gt;'GREEN',1=&gt;'YELLOW', 2=&gt;'RED');
		public $ANSI_BG = array('RED'=&gt;'[41m','GREEN'=&gt;'[42m','YELLOW'=&gt;'[43m','CYAN'=&gt;'[46m');
		public $ANSI_FG = array('RED'=&gt;'[1;31m','GREEN'=&gt;'[1;32m','YELLOW'=&gt;'[1;33m','CYAN'=&gt;'[1;36m');
		public $ANSI_SPECIAL = array('NORMAL'=&gt;'[0m');

		function UDPDEBUG($IP_ADDRESS, $PORT){
			$this-&gt;ESC_CHR = chr(27);
			$this-&gt;IP_ADDRESS = $IP_ADDRESS;
			$this-&gt;PORT = $PORT;
		}

		function SEND($STRING, $LEVEL = 1, $VERBOSE = FALSE)
		{
			$LEVEL = $this-&gt;LEVEL[$LEVEL];
			if($VERBOSE == TRUE){
				$OUTPUT = sprintf("[%s]:%s:%s%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG['CYAN'].$this-&gt;PORT,$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].str_pad($this-&gt;LEVEL_WORDS[$LEVEL], 9),$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL'], $STRING);
			}else{
				$OUTPUT = sprintf("%s\n",$this-&gt;ESC_CHR.$this-&gt;ANSI_FG[$this-&gt;LEVEL_COLORS[$LEVEL]].$STRING.$this-&gt;ESC_CHR.$this-&gt;ANSI_SPECIAL['NORMAL']);
			}
			$this-&gt;UPD_OBJECT = fsockopen("udp://" . $this-&gt;IP_ADDRESS, $this-&gt;PORT, $this-&gt;ERR_NO, $this-&gt;ERR_STR);
			if (!$this-&gt;UPD_OBJECT) {
				echo "ERROR IN UDP SYSTEM: $this-&gt;ERR_NO - $this-&gt;ERR_STR&lt;br /&gt;\n";
				return 0;
			}
			fwrite($this-&gt;UPD_OBJECT, $OUTPUT);
			fclose($this-&gt;UPD_OBJECT);
		}
	}
?&gt;

    </pre></div>
<p>Come back next week when we will modify our base UDPDEBUG class to add in array handling. This will enhance our debugging ability and open up for a future change of passing objects and even mysql record sets.</p>
<p><strong>UPDATE</strong>.<br />
Please visit part two of this article series at <a href="/2009/03/15/remote-debugging-with-udp-sockets-part-2/">Remote debugging with UDP sockets part 2</a>.</p>
<p>Till next week, code sexy.</p>
<p>&#8211;Terry Valladon</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/class' rel='tag' target='_self'>class</a>, <a class='technorati-link' href='http://technorati.com/tag/code' rel='tag' target='_self'>code</a>, <a class='technorati-link' href='http://technorati.com/tag/debugging' rel='tag' target='_self'>debugging</a>, <a class='technorati-link' href='http://technorati.com/tag/php' rel='tag' target='_self'>php</a>, <a class='technorati-link' href='http://technorati.com/tag/sockets' rel='tag' target='_self'>sockets</a>, <a class='technorati-link' href='http://technorati.com/tag/tutorial' rel='tag' target='_self'>tutorial</a>, <a class='technorati-link' href='http://technorati.com/tag/udp' rel='tag' target='_self'>udp</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.dirtytrolls.com/2009/02/11/remote-php-debugging-with-udp-sockets-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
