<?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>LaslowNET &#187; php5</title>
	<atom:link href="http://laslow.net/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://laslow.net</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 03:06:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A PHP-Based Server Monitor</title>
		<link>http://laslow.net/2010/10/22/a-php-based-server-monitor/</link>
		<comments>http://laslow.net/2010/10/22/a-php-based-server-monitor/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 17:46:54 +0000</pubDate>
		<dc:creator>Laslow</dc:creator>
				<category><![CDATA[Hack]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.laslow.net/?p=1043</guid>
		<description><![CDATA[The other day I decided that the little &#8216;Network Monitor&#8217; desktop gadget I was using to monitor my few servers just wasn&#8217;t cutting it. Instead, I wanted to make use of a spare iMac and have something a little flashier. A Google search for Server Monitors brought up a plethora of options that were either [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I decided that the little &#8216;Network Monitor&#8217; desktop gadget I was using to monitor my few servers just wasn&#8217;t cutting it. Instead, I wanted to make use of a spare iMac and have something a little flashier. A Google search for Server Monitors brought up a plethora of options that were either horribly ugly, platform specific, or just didn&#8217;t work the way I needed (most required that the target server be running some form of web server, such as IIS or Apache to retrieve headers to see if the server was up &#8211; most of my servers don&#8217;t run those). As such, I decided to write a small script from scratch.</p>
<p>I figured the easiest way to accomplish my goal of a platform-independent monitoring script was to use PHP. After enabling Apache2/PHP5 on my Snow Leopard-running iMac (a topic for another blog post later), I searched through the <a href="http://www.php.net/manual/en/language.functions.php" target="_blank">PHP.net function list</a> until I found <a href="http://php.net/manual/en/function.fsockopen.php" target="_blank">fsockopen()</a>. This function is quite ideal, as it will work with any open port. The first step was to make a quick function to utilize <em>fsockopen</em> and return some testable results:</p>
<blockquote>
<div id="_mcePaste">
<div id="_mcePaste">function checkServer($ip,$port)</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>{</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>$fp = fsockopen($ip,$port,$errno,$errstr,1);</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>if (!$fp)</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>{</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>return &#8216;Down&#8217;;</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>} else {</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>return &#8216;Up&#8217;;</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste"><span style="white-space: pre;"> </span>}</div>
</div>
</blockquote>
<p>I added this to a &lt;?php ?&gt; block in the &lt;head&gt;&lt;/head&gt; of the document &#8211; to call the function and perform the test, I used the following line below:</p>
<blockquote><p>$servername = checkServer(&#8217;192.168.1.100&#8242;,&#8217;53&#8242;);</p></blockquote>
<p>In this example I&#8217;m checking the availability of a DNS server, so I use port 53. When this runs, the $servername is set to either &#8216;Up&#8217; or &#8216;Down&#8217; depending on whether or not a connection can be opened on that port.</p>
<p>The only thing left now was to display this output. I made a fancy table-based page with graphics where each server is a cell and the background changes between green and red depending on the $servername value. However, all you <em>really</em> need is the code below in a &lt;?php ?&gt; block in the body of the page:</p>
<blockquote><p>echo(&#8216;Server <em>Example </em>Status: &#8216;.$servername);</p></blockquote>
<p>Changing <em>Example</em> to the name of your server. If you have more than one server to check, just make another variable, use the checkServer function to give it a value (make sure to change the IP address and use an open port!), and then add another echo line.</p>
<p>That&#8217;s it! To be fancy, you can add a javascript automagic page refresh to &#8211; just change the &lt;body&gt; tag to:</p>
<blockquote><p>&lt;body onLoad=&#8221;Javascript:timedRefresh(30000); display();&#8221;&gt;</p></blockquote>
<p>And put the following in the &lt;head&gt;&lt;/head&gt; section:</p>
<blockquote><p>&lt;script type=&#8221;text/Javascript&#8221;&gt;</p>
<p>&lt;!&#8211;</p>
<p>function timedRefresh(timeoutPeriod) {</p>
<p><span style="white-space: pre;"> </span>setTimeout(&#8220;location.reload(true);&#8221;,timeoutPeriod);</p>
<p>}</p>
<p>//  &#8211;&gt;</p>
<p>&lt;/script&gt;</p></blockquote>
<p>And you&#8217;re done! If the server is up, every 30 seconds your page will refresh and show:</p>
<blockquote><p>Server <em>Example</em> Status: Up</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://laslow.net/2010/10/22/a-php-based-server-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Installation on Server 2003 x86 with Apache2/PHP5/MySQL5</title>
		<link>http://laslow.net/2009/02/21/wordpress-installation-on-server-2003-x86-with-apache2php5mysql5/</link>
		<comments>http://laslow.net/2009/02/21/wordpress-installation-on-server-2003-x86-with-apache2php5mysql5/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 03:37:01 +0000</pubDate>
		<dc:creator>Laslow</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Apache2]]></category>
		<category><![CDATA[installation instructions]]></category>
		<category><![CDATA[mysql5]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.laslow.net/?p=7</guid>
		<description><![CDATA[(This assumes you already know how to actually install Apache2 and MySQL5 properly, and setup a database with a user for WordPress). A quick note about WordPress installations on Windows Server 2003. After installing Apache2, MySQL Server Community Edition, and extracting PHP5 (Protip: don&#8217;t use the installer, just download the .zip file and extract it [...]]]></description>
			<content:encoded><![CDATA[<p><em>(This assumes you already know how to actually install Apache2 and MySQL5 properly, and setup a database with a user for WordPress).</em></p>
<p>A quick note about WordPress installations on Windows Server 2003. After installing <a href="http://apache.org">Apache2</a>, <a href="http://mysql.org">MySQL Server Community Edition</a>, and extracting PHP5 (Protip: don&#8217;t use the installer, just download the .zip file and extract it to a folder on your server, eg. C:php), configure the <em>php.ini</em> file in the PHP directory as normal, with the following changes to avoid issues with MySQL not integrating with PHP correctly:</p>
<p>1) Set <em>extension_dir</em> to the <span style="text-decoration: underline;">absolute</span> path of the extensions directory. So if you extracted PHP to <em>C:php</em>, you need to set <em>extension_dir</em> to <em>&#8220;C:phpext&#8221;. </em>Do <span style="text-decoration: underline;"><em>not</em></span> use relative paths!</p>
<p>2) Remove the semi-colon from the line <em>extension=php_mysql.dll</em>.</p>
<p>3) Set the <em>upload_tmp_dir</em> path to an existing folder. I&#8217;d suggest making a new temp folder, such as <em>C:phptemp</em>.</p>
<p>4) Configure <em>mysql.default_port</em> and <em>mysql.default_host</em> with the correct values for your MySQL server.</p>
<p>5) Set the <em>doc_root</em> parameter to where-ever you plan on storing your the files for your site. This needs to be the same as the <em>document_root</em> parameter in Apache2&#8242;s <em>httpd.conf</em>.</p>
<p>Now you just need to configure Apache2 to correctly use PHP5. Add the following lines to <em>httpd.conf (</em>note the slashes used &#8211; don&#8217;t use backslashes!):</p>
<blockquote><p>LoadModule php5_module &#8220;c:/php/php5apache2_2.dll&#8221;<br />
AddType application/x-httpd-php .php<br />
PHPIniDir &#8220;C:/php&#8221;</p></blockquote>
<p>Even though the installation instructions included with PHP say to use <em>php5apache2.dll, </em>we have to use<em> php5apache2<strong>_2</strong>.dll</em>, otherwise Apache2 will fail to start. All that&#8217;s left now is to copy <em>libmysql.dll</em> and <em>php5ts.php</em> from the PHP directory to <em>C:WindowsSystem32</em>.</p>
<p>With this done, you should be able to restart Apache2, and you hopefully won&#8217;t get any errors! To test and make sure that PHP5 is working, and that MySQL5 is accessible, create a new file in your site root (the same folder that <em>doc_root</em> and <em>document_root</em> point to) called <em>info.php</em>, and put the following line in it:</p>
<blockquote><p>&lt;?php phpinfo(); ?&gt;</p></blockquote>
<p>Open your webbrowser, and type <em>http://localhost/info.php</em> in to the address bar, and you should get the standard PHP Info page. Do a search for <em>MySQL</em>, and you should have a heading for it. If so, you&#8217;re ready to install WordPress. If not, then double-check your configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://laslow.net/2009/02/21/wordpress-installation-on-server-2003-x86-with-apache2php5mysql5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

