<?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>Navarr&#039;s Tech Side &#187; PHP</title>
	<atom:link href="http://tech.navarr.me/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.navarr.me</link>
	<description>The Technical Side of my Life</description>
	<lastBuildDate>Tue, 07 Feb 2012 22:32:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='tech.navarr.me' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>How to create a socket server in PHP</title>
		<link>http://tech.navarr.me/2010/07/how-to-create-a-socket-server-in-php.html</link>
		<comments>http://tech.navarr.me/2010/07/how-to-create-a-socket-server-in-php.html#comments</comments>
		<pubDate>Wed, 30 Jun 2010 23:47:28 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[class::IRCServer]]></category>
		<category><![CDATA[class::SocketServer]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/?p=470</guid>
		<description><![CDATA[EDIT: If you need to submit bugs or want to improve my work, its now available on github! Ever tried searching for information on how to properly create a multi-client socket server in PHP?  You’ll get plenty of results with outdated and messy source code, some of which won’t even work. This was the my [...]]]></description>
			<content:encoded><![CDATA[<p><strong>EDIT: </strong>If you need to submit bugs or want to improve my work,<a href="https://github.com/navarr/PHP-SocketServer"> its now available on github</a>!</p>
<p>Ever tried searching for information on how to properly create a multi-client socket server in PHP?  You’ll get plenty of results with outdated and messy source code, some of which won’t even work.</p>
<p>This was the my state a couple days ago when I decided that I wanted to build an IRC server.  The why is not important… (<em>For the fun of building an IRC Server</em>).  So I googled around a <span style="text-decoration: line-through;">hell of a lot</span> bit until I finally found some code that worked on its own, and quickly built a semi-functional IRC server using it, and headed off to sleep at 5am.</p>
<p>The next day I was very, very happy with the results of my hard labor, but it wasn’t good enough, so I started re-writing it from scratch as an Object, and thus I created <a href="http://gist.github.com/457900">class::IRCServer</a>.</p>
<p>Today, once I felt that I was finished screwing around with my newly built IRCd, I decided to modify the function enough to be used on its own as a socket server, to share with the world.</p>
<p>And thus, <a href="http://gist.github.com/459321">class::SocketServer</a> was created.</p>
<pre><div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
	<span style="color: #666666; font-style: italic;">/*!	@class		SocketServer
		@author		Navarr Barnier
		@abstract 	A Framework for creating a multi-client server using the PHP language.
	 */</span>
	<span style="color: #000000; font-weight: bold;">class</span> SocketServer
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*!	@var		config
			@abstract	Array - an array of configuration information used by the server.
		 */</span>
		protected <span style="color: #000088;">$config</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		hooks
			@abstract	Array - a dictionary of hooks and the callbacks attached to them.
		 */</span>
		protected <span style="color: #000088;">$hooks</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		master_socket
			@abstract	resource - The master socket used by the server.
		 */</span>
		protected <span style="color: #000088;">$master_socket</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		max_clients
			@abstract	unsigned int - The maximum number of clients allowed to connect.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$max_clients</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		max_read
			@abstract	unsigned int - The maximum number of bytes to read from a socket at a single time.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$max_read</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		clients
			@abstract	Array - an array of connected clients.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$clients</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	__construct
			@abstract	Creates the socket and starts listening to it.
			@param		string	- IP Address to bind to, NULL for default.
			@param		int	- Port to bind to
			@result		void
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bind_ip</span><span style="color: #339933;">,</span><span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<a href="http://www.php.net/set_time_limit"><span style="color: #990000;">set_time_limit</span></a><span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ip&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bind_ip</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$port</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/socket_create"><span style="color: #990000;">socket_create</span></a><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span> SOCK_STREAM<span style="color: #339933;">,</span> 0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/socket_bind"><span style="color: #990000;">socket_bind</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ip&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Issue Binding&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/socket_getsockname"><span style="color: #990000;">socket_getsockname</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$bind_ip</span><span style="color: #339933;">,</span><span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/socket_listen"><span style="color: #990000;">socket_listen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Listenting for connections on <span style="color: #006699; font-weight: bold;">{$bind_ip}</span>:<span style="color: #006699; font-weight: bold;">{$port}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	hook
			@abstract	Adds a function to be called whenever a certain action happens.  Can be extended in your implementation.
			@param		string	- Command
			@param		callback- Function to Call.
			@see		unhook
			@see		trigger_hooks
			@result		void
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">,</span><span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_search"><span style="color: #990000;">array_search</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$function</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	unhook
			@abstract	Deletes a function from the call list for a certain action.  Can be extended in your implementation.
			@param		string	- Command
			@param		callback- Function to Delete from Call List
			@see		hook
			@see		trigger_hooks
			@result		void
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unhook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span><span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_search"><span style="color: #990000;">array_search</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_search"><span style="color: #990000;">array_search</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_funcs</span><span style="color: #339933;">,</span><span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_funcs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	loop_once
			@abstract	Runs the class's actions once.
			@discussion	Should only be used if you want to run additional checks during server operation.  Otherwise, use infinite_loop()
			@param		void
			@see		infinite_loop
			@result 	bool	- True
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loop_once<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Setup Clients Listen Socket For Reading</span>
			<span style="color: #000088;">$read</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_clients</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</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><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$read</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">+</span> 1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Set up a blocking call to socket_select</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/socket_select"><span style="color: #990000;">socket_select</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$read</span><span style="color: #339933;">,</span><span style="color: #000088;">$write</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$except</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tv_sec</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//	SocketServer::debug(&quot;Problem blocking socket_select?&quot;);</span>
				<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Handle new Connections</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">,</span> <span style="color: #000088;">$read</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_clients</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</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><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$temp_sock</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketServerClient<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">master_socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trigger_hooks</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CONNECT&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_clients</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Too many clients...   &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Handle Input</span>
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_clients</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// for each client</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span> <span style="color: #000088;">$read</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/socket_read"><span style="color: #990000;">socket_read</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_read</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
						<span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						<span style="color: #b1b100;">else</span>
						<span style="color: #009900;">&#123;</span>
							SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$i}</span>@{<span style="color: #006699; font-weight: bold;">$this-&gt;clients</span>[<span style="color: #006699; font-weight: bold;">$i</span>]-&gt;ip} --&gt; <span style="color: #006699; font-weight: bold;">{$input}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trigger_hooks</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INPUT&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	disconnect
			@abstract	Disconnects a client from the server.
			@param		int	- Index of the client to disconnect.
			@param		string	- Message to send to the hooks
			@result		void
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> disconnect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client_index</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client_index</span><span style="color: #339933;">;</span>
			SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Client <span style="color: #006699; font-weight: bold;">{$i}</span> from {<span style="color: #006699; font-weight: bold;">$this-&gt;clients</span>[<span style="color: #006699; font-weight: bold;">$i</span>]-&gt;ip} Disconnecting&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trigger_hooks</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DISCONNECT&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	trigger_hooks
			@abstract	Triggers Hooks for a certain command.
			@param		string	- Command who's hooks you want to trigger.
			@param		object	- The client who activated this command.
			@param		string	- The input from the client, or a message to be sent to the hooks.
			@result		void
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> trigger_hooks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">,&amp;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span><span style="color: #000088;">$input</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><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hooks</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Triggering Hook '<span style="color: #006699; font-weight: bold;">{$function}</span>' for '<span style="color: #006699; font-weight: bold;">{$command}</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$continue</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/call_user_func"><span style="color: #990000;">call_user_func</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$continue</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	infinite_loop
			@abstract	Runs the server code until the server is shut down.
			@see		loop_once
			@param		void
			@result		void
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> infinite_loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">do</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loop_once</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	debug
			@static
			@abstract	Outputs Text directly.
			@discussion	Yeah, should probably make a way to turn this off.
			@param		string	- Text to Output
			@result		void
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> debug<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$text}</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	socket_write_smart
			@static
			@abstract	Writes data to the socket, including the length of the data, and ends it with a CRLF unless specified.
			@discussion	It is perfectly valid for socket_write_smart to return zero which means no bytes have been written. Be sure to use the === operator to check for FALSE in case of an error.
			@param		resource- Socket Instance
			@param		string	- Data to write to the socket.
			@param		string	- Data to end the line with.  Specify a &quot;&quot; if you don't want a line end sent.
			@result		mixed	- Returns the number of bytes successfully written to the socket or FALSE on failure. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.
		*/</span>
		<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> socket_write_smart<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span><span style="color: #000088;">$crlf</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt; -- <span style="color: #006699; font-weight: bold;">{$string}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$crlf</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$string}</span><span style="color: #006699; font-weight: bold;">{$crlf}</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <a href="http://www.php.net/socket_write"><span style="color: #990000;">socket_write</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span><a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	__get
			@abstract	Magic Method used for allowing the reading of protected variables.
			@discussion	You never need to use this method, simply calling $server-&gt;variable works because of this method's existence.
			@param		string	- Variable to retrieve
			@result		mixed	- Returns the reference to the variable called.
		*/</span>
		<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">&amp;</span>__get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*!	@class		SocketServerClient
		@author		Navarr Barnier
		@abstract	A Client Instance for use with SocketServer
	 */</span>
	<span style="color: #000000; font-weight: bold;">class</span> SocketServerClient
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*!	@var		socket
			@abstract	resource - The client's socket resource, for sending and receiving data with.
		 */</span>
		protected <span style="color: #000088;">$socket</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		ip
			@abstract	string - The client's IP address, as seen by the server.
		 */</span>
		protected <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		hostname
			@abstract	string - The client's hostname, as seen by the server.
			@discussion	This variable is only set after calling lookup_hostname, as hostname lookups can take up a decent amount of time.
			@see		lookup_hostname
		 */</span>
		protected <span style="color: #000088;">$hostname</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@var		server_clients_index
			@abstract	int - The index of this client in the SocketServer's client array.
		 */</span>
		protected <span style="color: #000088;">$server_clients_index</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	__construct
			@param		resource- The resource of the socket the client is connecting by, generally the master socket.
			@param		int	- The Index in the Server's client array.
			@result		void
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_clients_index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/socket_accept"><span style="color: #990000;">socket_accept</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to Accept&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;New Client Connected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/socket_getpeername"><span style="color: #990000;">socket_getpeername</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	lookup_hostname
			@abstract	Searches for the user's hostname and stores the result to hostname.
			@see		hostname
			@param		void
			@result		string	- The hostname on success or the IP address on failure.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> lookup_hostname<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hostname</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/gethostbyaddr"><span style="color: #990000;">gethostbyaddr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hostname</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*!	@function	destroy
			@abstract	Closes the socket.  Thats pretty much it.
			@param		void
			@result		void
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<a href="http://www.php.net/socket_close"><span style="color: #990000;">socket_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">&amp;</span>__get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div></pre>
<p>class::SocketServer does all the functions necessary for a server.  It binds to the IP address and starts listening to the port.  Its easy to specify a maximum number of clients to allow, and the way its coded makes it easily modified.</p>
<p>Here is an example of a server (using this class) that listens for a user to send a string, and then echoes the reverse of that string back to the user.</p>
<pre><div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
	<span style="color: #666666; font-style: italic;">// This is PHP5 Code, by the way.</span>
&nbsp;
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SocketServer.class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Include the Class File</span>
	<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketServer<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>31337<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Create a Server binding to the default IP address (null) and listen to port 31337 for connections</span>
	<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_clients</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Allow no more than 10 people to connect at a time</span>
	<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hook</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CONNECT&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;handle_connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Run handle_connect everytime someone connects</span>
	<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hook</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INPUT&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;handle_input&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Run handle_input whenever text is sent to the server</span>
	<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">infinite_loop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Run Server Code Until Process is terminated.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * All hooked functions are sent the parameters $server (The server class), $client (the connection), and $input (anything sent, if anything was sent)
	 * You should save the variables $server and $client using an ampersand (&amp;) to make sure they are references to the objects and not duplications.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> handle_connect<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,&amp;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">socket_write_smart</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;String? &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Outputs 'String? ' without a Line Ending</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> handle_input<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,&amp;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$trim</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Trim the input, Remove Line Endings and Extra Whitespace.</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trim</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;quit&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// User Wants to quit the server</span>
		<span style="color: #009900;">&#123;</span>
			SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">socket_write_smart</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Oh... Goodbye...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Give the user a sad goodbye message, meany!</span>
			<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_clients_index</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Disconnect this client.</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ends the function</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strrev"><span style="color: #990000;">strrev</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trim</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Reverse the String</span>
&nbsp;
		SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">socket_write_smart</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Send the Client back the String</span>
		SocketServer<span style="color: #339933;">::</span><span style="color: #004000;">socket_write_smart</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;String? &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Request Another String</span>
	<span style="color: #009900;">&#125;</span></pre></div></div></pre>
<p>In essence, this class allows you to handle sockets in PHP. <strong><em>Beautifully</em></strong> handle sockets in PHP, that is.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/07/how-to-create-a-socket-server-in-php.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Magical Typesetting in PHP</title>
		<link>http://tech.navarr.me/2010/06/magical-typesetting-in-php.html</link>
		<comments>http://tech.navarr.me/2010/06/magical-typesetting-in-php.html#comments</comments>
		<pubDate>Mon, 28 Jun 2010 10:32:39 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[class::GenericVariable]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[typesetting]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2010/06/magical-typesetting-in-php.html</guid>
		<description><![CDATA[So, well working for Route 50 I came up with a fantastic idea for “typesetting” that well exceeded the norm.  Something we constantly have issues with is what type of string was sent to MySQL originally (some of us have different conventional ideas about where escaping HTML should be located.) as well as outputting that [...]]]></description>
			<content:encoded><![CDATA[<p>So, well working for <a href="http://route50.net/" target="_blank">Route 50</a> I came up with a fantastic idea for “typesetting” that well exceeded the norm.  Something we constantly have issues with is what type of string was sent to MySQL originally (some of us have different conventional ideas about where escaping HTML should be located.) as well as outputting that string in its correct format.</p>
<p>Me, with my fantastic idea, came up with a couple variables classes that I put in a file named <a href="http://gist.github.com/451216">class_typesetting.php</a>.  The version on gist.github is slightly modified from the original version on the server.</p>
<p>It creates three classes, GenericVariable, String, and Number.  So far we haven’t used GenericVariable, but since the introduction of the classes I’ve taken it upon myself to introduce them to any new code I write.  When we create Core v5 (which will Objectify everything) strings taken from SQL will automatically be re-stored as String class variables.</p>
<p>First, lets examine some useful functionality.</p>
<pre><div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>“title”<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &lt;strong&gt;Hello 'World'&lt;/strong&gt;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
HTML Output: <span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">html</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> (&amp;lt;strong&amp;gt;Hello 'World'&amp;lt;/strong&amp;gt;)
Text Output: <span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> (Hello 'World')
SQL Output: <span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sql</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> (&lt;strong&gt;Hello \'World\'&lt;/strong&gt;)
HTML Attribute Output: <span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">html_attr</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>(&amp;lt;strong&amp;gt;Hello &amp;#039;World&amp;#039;&amp;lt;/strong&amp;gt;)</pre></div></div></pre>
<p>This allows for quick and easy access to the variables without having to worry about escaping them.</p>
<p>I recommend you hit the download link (class_typesetting.php) and play around with it.  Tell me about anything that’s not working correctly and if possible implement it in your future code.  (This means I’m putting this code in the “Public Domain”).</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/06/magical-typesetting-in-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>simpleTAPI is Broken</title>
		<link>http://tech.navarr.me/2010/02/simpletapi-is-broken.html</link>
		<comments>http://tech.navarr.me/2010/02/simpletapi-is-broken.html#comments</comments>
		<pubDate>Sat, 20 Feb 2010 23:34:08 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2010/02/simpletapi-is-broken.html</guid>
		<description><![CDATA[Apparently I’ve completely broken simpleTAPI somewhere between Build 27 and Build 30.&#160; I thought I had fixed it with Build 29, but it seems that I was mistaken. In lieu of this, I am putting simpleTAPI on a temporary hiatus.&#160; I will be re-constructing it from scratch (though, probably looking back and using a good [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently I’ve completely broken simpleTAPI somewhere between Build 27 and Build 30.&#160; I thought I had fixed it with Build 29, but it seems that I was mistaken.</p>
<p>In lieu of this, I am putting simpleTAPI on a temporary hiatus.&#160; I will be re-constructing it from scratch (though, probably looking back and using a good bit of the original code).&#160; The next version should have several configurable options, and will hopefully interact with the Twitter API much better than the previous versions.</p>
<p>Build 30 was supposed to return results as an array([“TAPI”] =&gt; data, [“result”] =&gt; data).&#160; But all I’m getting from it at the moment is “Unable to Authenticate User.”</p>
<p>Those wanting to use simpleTAPI should use <a href="http://github.com/navarr/simpleTAPI/commit/cc1567ce27c270a4314ba030f14d20684b128bf0">Build 27</a>, though you will have to deal with some minor quirks in the way results are returned.&#160; (the TAPI array is simply appended to the results array, making things slightly complicated if you don’t unset($result[“TAPI”]);</p>
<p>What will be simpleTAPI 0.4 should have better error handling, better return data, and better built-in caching.&#160; I’m also hoping to build in support for xAuth and Delegated OAuth, if at all possible.&#160; (Though probably not since simpleTAPI is built upon another OAuth library).</p>
<p>So, I’m asking for any and all feature requests.&#160; Is there something about simpleTAPI you don’t like or want to be improved?&#160; Please, post in the comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/02/simpletapi-is-broken.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Voice OMS Code on Github</title>
		<link>http://tech.navarr.me/2009/11/google-voice-oms-code-on-github.html</link>
		<comments>http://tech.navarr.me/2009/11/google-voice-oms-code-on-github.html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 00:52:34 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[子猫ちゃん GV OMS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Google Voice]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[OMS]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/google-voice-oms-code-on-github.html</guid>
		<description><![CDATA[I pushed the 子猫ちゃん Google Voice OMS service’s code to github, so you can now download it – albeit, to make it work it’ll take a lot of hacking and a lot more editing. Either way, I’ve gotten no donations and no offers for free SSL hosting, so it looks like this project just will [...]]]></description>
			<content:encoded><![CDATA[<p>I pushed the 子猫ちゃん Google Voice OMS service’s code to github, so you can now download it – albeit, to make it work it’ll take a lot of hacking and a lot more editing.</p>
<p>Either way, I’ve gotten no donations and no offers for free SSL hosting, so it looks like this project just will not be seeing the light of day.&#160; It’s a shame, I worked a long time to make it work, and it’s obviously something a lot of business professionals would be able to find a use for.</p>
<p>Oh well, you can find the project <a href="http://github.com/navarr/Google-Voice-OMS">on github</a>.</p>
<p>Remember to abide by the Usage License!</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/google-voice-oms-code-on-github.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Voice in Outlook</title>
		<link>http://tech.navarr.me/2009/11/google-voice-in-outlook.html</link>
		<comments>http://tech.navarr.me/2009/11/google-voice-in-outlook.html#comments</comments>
		<pubDate>Wed, 25 Nov 2009 22:15:27 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[子猫ちゃん GV OMS]]></category>
		<category><![CDATA[Google Voice]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[OMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[wsdl]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/google-voice-in-outlook.html</guid>
		<description><![CDATA[EDIT: I managed to bring this into being thanks to other people generously letting it run on their servers (though unfortunately I can't vouch for the security).  You can check it out at http://www.gvoms.com. Additionally, I've also made the source code available over at https://github.com/navarr/Google-Voice-OMS If you’re a regular reader to my blog, I’m sure [...]]]></description>
			<content:encoded><![CDATA[<p><strong>EDIT</strong>: I managed to bring this into being thanks to other people generously letting it run on their servers (though unfortunately I can't vouch for the security).  You can check it out at <a href="http://gvoms.com">http://www.gvoms.com</a>.<br />
Additionally, I've also made the source code available over at <a href="https://github.com/navarr/Google-Voice-OMS">https://github.com/navarr/Google-Voice-OMS</a></p>
<p>If you’re a regular reader to my blog, I’m sure you read yesterday’s post about how <a href="http://tech.gtaero.net/2009/11/how-google-voice-could-gain-a-head-in-the-business-world.html">Google Voice could gain a head in the business world</a>.  At that time, my dream of connecting Google Voice and Outlook via OMS was far from completion, with the only work I’d managed to accomplish being a simple reading over of the related technologies.</p>
<p>Well, late last night a certain gear clicked in my brain, and I spent the entire night awake and coding PHP on a local XAMPP server.  But my end result was fruitful – I finished successfully coding an Outlook Mobile Service that allows the delivery of SMS through the Google Voice system.</p>
<p>Here is a video showing it off:</p>
<div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:cf70ab77-6981-4b19-baee-c2c8a1936a1e" class="wlWriterEditableSmartContent" style="width: 480px; display: block; float: none; margin-left: auto; margin-right: auto; padding: 0px;">
<div><object width="480" height="385" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube-nocookie.com/v/Oa_U-KZyhHI&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed width="480" height="385" type="application/x-shockwave-flash" src="http://www.youtube-nocookie.com/v/Oa_U-KZyhHI&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></div>
</div>
<p>I’m not yet prepared to release the source code for this, though.  (Messy, Messy, Mess! as Double D would say).  There’s a lot in my mind about it, it took a lot of work and I’m not ready to see forks and duplicate services pop up.  (Sorry guys =S).  Be on the look out for follow up posts that describe some of the technologies I had to learn to make this possible.</p>
<p>Oh, also – If you’d like; Help sponsor this project (I can’t afford to make it public ATM) with either Free (VERIFIED) SSL Hosting for a subdomain of a domain I own [<a href="mailto:navarr+oms@gtaero.net">contact me</a>], or the money to make it public using my current host (<strong>$62.40/yr</strong>) [<a href="http://www.dreamhost.com/donate.cgi?id=12437">donate through my host</a>].  I would be most appreciative if you could offer either of these to get this thing up and running!</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/google-voice-in-outlook.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>simpleTAPI v0.2.1 &#8211; Build 16 (Twitter API Library)</title>
		<link>http://tech.navarr.me/2009/11/simpletapi-v0-2-1-build-16-twitter-api-library.html</link>
		<comments>http://tech.navarr.me/2009/11/simpletapi-v0-2-1-build-16-twitter-api-library.html#comments</comments>
		<pubDate>Sun, 22 Nov 2009 21:58:16 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/simpletapi-v0-2-1-build-16-twitter-api-library.html</guid>
		<description><![CDATA[I’ve renamed the Twitter API Library to “simpleTAPI.”&#160; Yes, I’m not very good at names when it comes to this sort of thing.&#160; We’ve jumped forward two builds since my last post here. Build 15 The addition of a quick variable, bool Twitter::geo_enabled. Returns TRUE if the user has turned on geo functionality, FALSE if [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve renamed the Twitter API Library to “simpleTAPI.”&#160; Yes, I’m not very good at names when it comes to this sort of thing.&#160; We’ve jumped forward two builds since my last post here.</p>
<p><strong>Build 15</strong></p>
<ul>
<li>The addition of a quick variable, <em>bool</em> Twitter::geo_enabled.      <br />Returns TRUE if the user has turned on geo functionality, FALSE if not.</li>
</ul>
<p><strong>Version 0.2.1</strong></p>
<ul>
<li>Re-Organized classes.&#160; Separated TwitterOAuth and OAuth into separate files, and moved them along with Twitter into a “twitter” folder.&#160; All classes can be loaded simply by including <strong>Twitter.lib.php</strong>.</li>
</ul>
<p><strong>Build 16</strong></p>
<ul>
<li>Fixed a minor inconsistency in TWML where different functions returned different links to a twitter user’s profile.</li>
<li>Fixed a bug where specifying screennameonly=TRUE for TWML::name resulted in an empty hyperlink.</li>
</ul>
<p><strong>Examples</strong></p>
<ul>
<li>Started work on Example files to teach how to use simpleTAPI.&#160; Currently, the only one included is a basic Update script.&#160; This file includes logging in, updating a status, and returning the same status as well as some basic TWML examples.</li>
</ul>
<p>So, enjoy!&#160; I will continue to improve this library.&#160; Please remember to post all issues and feature requests either on this blog or the <a href="http://github.com/navarr/simpleTAPI">github page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/simpletapi-v0-2-1-build-16-twitter-api-library.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API Library Build 13 (Breaking Change)</title>
		<link>http://tech.navarr.me/2009/11/twitter-api-library-build-13-breaking-change.html</link>
		<comments>http://tech.navarr.me/2009/11/twitter-api-library-build-13-breaking-change.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 23:21:52 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/twitter-api-library-build-13-breaking-change.html</guid>
		<description><![CDATA[I pushed Build 13 today.&#160; This build adds the recent addition of descriptions to a user’s list. This change breaks: TwitterAPI::lists_create and TwitterAPI::lists_update The new profiles for these commands are as follows: TwitterAPI::lists_create( str $name [, str $description = NULL [, bool $privacy = TWITTER_PRIVACY_PUBLIC ] ] ) TwitterAPI::lists_update( str $name [, str $new_name = [...]]]></description>
			<content:encoded><![CDATA[<p>I pushed <a href="http://github.com/navarr/PHP-Twitter-API-Library/commit/f27608a709ac04676df68a3689845c72eb4755cf">Build 13</a> today.&#160; This build adds the recent addition of descriptions to a user’s list.</p>
<p>This change breaks:</p>
<ul>
<li>TwitterAPI::<strong>lists_create</strong> <em>and</em></li>
<li>TwitterAPI::<strong>lists_update</strong></li>
</ul>
<p>The new profiles for these commands are as follows:</p>
<blockquote><p>TwitterAPI::<strong>lists_create</strong>( <em>str</em> $name [, <em>str</em> $description = NULL [, <em>bool</em> $privacy = TWITTER_PRIVACY_PUBLIC ] ] )</p>
<p>TwitterAPI::<strong>lists_update</strong>( <em>str</em> $name [, <em>str</em> $new_name = NULL [, <em>str</em> $description = NULL [, <em>bool</em> $privacy = NULL ] ] ] )</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/twitter-api-library-build-13-breaking-change.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API Library Build 12</title>
		<link>http://tech.navarr.me/2009/11/twitter-api-library-build-12.html</link>
		<comments>http://tech.navarr.me/2009/11/twitter-api-library-build-12.html#comments</comments>
		<pubDate>Wed, 18 Nov 2009 00:03:34 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/twitter-api-library-build-12.html</guid>
		<description><![CDATA[If you’ve been watching this blog, you’ll notice I skipped Build 11 – It was small, and was trumped by its quick replacement – Build 12.&#160; Builds 11 and 12 fixed five previous known issues, while build 12 fixed a non-issue with build 11.&#160; Fixes listed below: The following now work with all users: Twitter::get_sn_from_id() [...]]]></description>
			<content:encoded><![CDATA[<p>If you’ve been watching this blog, you’ll notice I skipped Build 11 – It was small, and was trumped by its quick replacement – Build 12.&#160; Builds 11 and 12 fixed five previous known issues, while build 12 fixed a non-issue with build 11.&#160; Fixes listed below:</p>
<ul>
<li>The following now work with all users:
<ul>
<li>Twitter::get_sn_from_id() </li>
<li>Twitter::get_name_from_id() </li>
<li>Twitter::get_id_from_sn() </li>
<li>TWML::name() </li>
<li>TWML::profile_pic() </li>
</ul>
</li>
<li>Addition of User Cache commands for use by TWML and the get_x_from_y() commands. </li>
</ul>
<p>As always, the most recent build is available at <a href="http://github.com/navarr/PHP-Twitter-API-Library">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/twitter-api-library-build-12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API Library Version 0.2 Build 10</title>
		<link>http://tech.navarr.me/2009/11/twitter-api-library-version-0-2-build-10.html</link>
		<comments>http://tech.navarr.me/2009/11/twitter-api-library-version-0-2-build-10.html#comments</comments>
		<pubDate>Tue, 17 Nov 2009 21:11:00 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/twitter-api-library-version-0-2-build-10.html</guid>
		<description><![CDATA[I pushed Version 2 Build 10 of the Twitter API Library to github.&#160; This new version still does not fix any of the previous errors, so the changelog is quite minor. Updated to TwitterOAuth v0.2-beta "fixes several bugs" Support for OAuth 1.0a Added a boolean return to require_login().]]></description>
			<content:encoded><![CDATA[<p>I pushed Version 2 Build 10 of the Twitter API Library to <a href="http://github.com/navarr/PHP-Twitter-API-Library">github</a>.&#160; This new version still does not fix any of the previous errors, so the changelog is quite minor.</p>
<ul>
<li>Updated to <a href="http://github.com/abraham/twitteroauth">TwitterOAuth</a> v0.2-beta
<ul>
<li>"fixes several bugs"</li>
<li>Support for OAuth 1.0a</li>
</ul>
</li>
<li>Added a boolean return to <strong>require_login</strong>().</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/twitter-api-library-version-0-2-build-10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API Library Build 9</title>
		<link>http://tech.navarr.me/2009/11/twitter-api-library-build-9.html</link>
		<comments>http://tech.navarr.me/2009/11/twitter-api-library-build-9.html#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:24:57 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[simpleTAPI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2009/11/twitter-api-library-build-9.html</guid>
		<description><![CDATA[I’ve pushed Build 9 of the Twitter API Library to github today.&#160; Interesting thing, it adds a few missing API features but does not yet fix any of the previous problems. New features are all Authenticated API Calls: search trends trends_current trends_daily trends_weekly users_search trends_available trends_location Yes, that means that we’ve added support for the [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve pushed Build 9 of the Twitter API Library to <a href="http://github.com/navarr/PHP-Twitter-API-Library">github</a> today.&#160; Interesting thing, it adds a few missing API features but does not yet fix any of the previous problems.</p>
<p>New features are all Authenticated API Calls:</p>
<ul>
<li>search</li>
<li>trends</li>
<li>trends_current</li>
<li>trends_daily</li>
<li>trends_weekly</li>
<li>users_search</li>
<li>trends_available</li>
<li>trends_location</li>
</ul>
<p>Yes, that means that we’ve added support for the following portions of the twitter api:</p>
<ul>
<li>Search</li>
<li>Trends</li>
<li>User Search</li>
<li>Local Trends</li>
</ul>
<p>Enjoy, and as always please report any and all errors you get.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2009/11/twitter-api-library-build-9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

