<?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>gEt DoWn ToNiGhT</title>
	<atom:link href="http://www.getdowntonight.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.getdowntonight.co.uk</link>
	<description>amusingly digressive progressive discussions</description>
	<lastBuildDate>Fri, 11 May 2012 13:09:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Full refresh in Mac Firefox</title>
		<link>http://www.getdowntonight.co.uk/2012/05/full-refresh-in-mac-firefox/</link>
		<comments>http://www.getdowntonight.co.uk/2012/05/full-refresh-in-mac-firefox/#comments</comments>
		<pubDate>Fri, 11 May 2012 13:07:19 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Science and Tech]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[refresh]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=622</guid>
		<description><![CDATA[After a  long time of clearing my cache out regularly for CSS / Javascript caching issues &#8211; I finally found out how to do a full refresh in Firefox on a Mac (clear cache etc). CMD + SHIFT + R.]]></description>
			<content:encoded><![CDATA[<p>After a  long time of clearing my cache out regularly for CSS / Javascript caching issues &#8211; I finally found out how to do a full refresh in Firefox on a Mac (clear cache etc).</p>
<pre>CMD + SHIFT + R.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2012/05/full-refresh-in-mac-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example backup restore of MySQL databases</title>
		<link>http://www.getdowntonight.co.uk/2012/05/example-backup-restore-of-mysql-databases/</link>
		<comments>http://www.getdowntonight.co.uk/2012/05/example-backup-restore-of-mysql-databases/#comments</comments>
		<pubDate>Sun, 06 May 2012 15:31:13 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=618</guid>
		<description><![CDATA[Quite often I need to backup a MySQL database, compress it, copy the data to another machine, then re-extract the data to MySQL. Here is the process I go through for doing that. mysqldump -p my_database_name &#62; my_database_name_2012_05_06.sql gzip my_database_name_2012_05_06.sql scp my_database_name_2012_05_06.gz root@server2:/tmp ssh root@server2 cd /tmp gunzip my_database_name_2012_05_06.gz mysql -p my_database_name &#60; /tmp/my_database_name_2012_05_06.sql]]></description>
			<content:encoded><![CDATA[<p>Quite often I need to backup a MySQL database, compress it, copy the data to another machine, then re-extract the data to MySQL.</p>
<p>Here is the process I go through for doing that.</p>
<ul>
<li>
<pre><strong>mysqldump</strong> -p my_database_name &gt; my_database_name_2012_05_06.sql</pre>
</li>
<li>
<pre><strong>gzip</strong> my_database_name_2012_05_06.sql</pre>
</li>
<li>
<pre><strong>scp</strong> my_database_name_2012_05_06.gz root@server2:/tmp</pre>
</li>
<li>
<pre><strong>ssh</strong> root@server2</pre>
</li>
<li>
<pre><strong>cd</strong> /tmp</pre>
</li>
<li>
<pre><strong>gunzip</strong> my_database_name_2012_05_06.gz</pre>
</li>
<li>
<pre><strong>mysql</strong> -p my_database_name &lt; /tmp/my_database_name_2012_05_06.sql</pre>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2012/05/example-backup-restore-of-mysql-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom parameters and source on jQuery autocomplete</title>
		<link>http://www.getdowntonight.co.uk/2012/04/custom-parameters-and-source-on-jquery-autocomplete/</link>
		<comments>http://www.getdowntonight.co.uk/2012/04/custom-parameters-and-source-on-jquery-autocomplete/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 15:11:03 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=607</guid>
		<description><![CDATA[I have been working on converting our custom drop-down boxes within a php/jquery based app to use the jQuery UI &#8216;autocomplete&#8217; tool, so that we can have keyboard-control over the selection choices (which our own code doesn&#8217;t have). It took me quite a while to work out how to send custom parameters from other autocomplete [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on converting our custom drop-down boxes within a php/jquery based app to use the jQuery UI &#8216;autocomplete&#8217; tool, so that we can have keyboard-control over the selection choices (which our own code doesn&#8217;t have).</p>
<p>It took me quite a while to work out how to send custom parameters from other autocomplete boxes on the same page to the URL that gets our source JSON data, but after lots of playing around and searching on the web &#8211; I think I have finally cracked it &#8211; and I am recording it here in case I forget in the future!</p>
<p>2 parts. A PHP page for generating JSON data to use in the drop down, and a HTML/jQuery page that sets up the UI tool.</p>
<p>Here is the PHP page that I use to collect and return data in JSON format, based on some parameters given in a variety of ways:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$category</span>       <span style="color: #339933;">=</span> get_input_request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;category&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$description</span>    <span style="color: #339933;">=</span> get_input_request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;term&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$select_field</span>   <span style="color: #339933;">=</span> get_input_request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;selectField&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$select_value</span>   <span style="color: #339933;">=</span> get_input_request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;selectValue&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$order_by</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$xref_data</span>      <span style="color: #339933;">=</span> get_xref_values<span style="color: #009900;">&#40;</span><span style="color: #000088;">$category</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_by</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span><span style="color: #339933;">,</span> <span style="color: #000088;">$select_field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$select_value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$str</span>            <span style="color: #339933;">=</span> get_autocomplete_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xref_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here is the jQuery code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#libraryLocation&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    matchContains<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    minLength<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
    source<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/dropDowns/autoXref.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            category<span style="color: #339933;">:</span> <span style="color: #3366CC;">'location'</span><span style="color: #339933;">,</span>
            selectField<span style="color: #339933;">:</span> <span style="color: #3366CC;">'format'</span><span style="color: #339933;">,</span>
            selectValue<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#libraryDepot'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            term<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#libraryLocation'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            response<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#libraryLocation&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2012/04/custom-parameters-and-source-on-jquery-autocomplete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Take a remote screenshot</title>
		<link>http://www.getdowntonight.co.uk/2012/04/take-a-remote-screenshot/</link>
		<comments>http://www.getdowntonight.co.uk/2012/04/take-a-remote-screenshot/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 21:03:40 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=603</guid>
		<description><![CDATA[If you need to take a screenshot of a machine and you only have terminal access &#8211; you can do the following: DISPLAY=&#34;:0.0&#34;; export DISPLAY; import -window root screengrab.png Then you can download the file using SCP: scp -P 22 sam@yourwebserver.com:screengrab.png ./screengrab.png]]></description>
			<content:encoded><![CDATA[<p>If you need to take a screenshot of a machine and you only have terminal access &#8211; you can do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">DISPLAY=&quot;:0.0&quot;; export DISPLAY; import -window root screengrab.png</pre></div></div>

<p>Then you can download the file using SCP:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">scp -P 22 sam@yourwebserver.com:screengrab.png ./screengrab.png</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2012/04/take-a-remote-screenshot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Page for sending JSON data as string to web-service</title>
		<link>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/</link>
		<comments>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:56:04 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=569</guid>
		<description><![CDATA[Just realised it has been a year since I posted anything on here! Time really flies when you&#8217;re busy! I remember when I was first starting off with jQuery, JSON and all that jazz that I struggled to find some simple examples of how to do things like send data to a web-service. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Just realised it has been a year since I posted anything on here! Time really flies when you&#8217;re busy!</p>
<p>I remember when I was first starting off with jQuery, JSON and all that jazz that I struggled to find some simple examples of how to do things like send data to a web-service. </p>
<p>Here is a quick example of how to send some JSON data (as a single post field) to a web service, using jQuery&#8217;s post method. </p>
<p>Keep in mind that if you are posting to another domain you may need to use something called jsonP &#8211; but if you are just learning, this is a good starting point!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;JSON Web Service Demo&lt;/title&gt;
&nbsp;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&nbsp;
        &lt;script src=&quot;http://code.jquery.com/jquery-1.7.1.min.js&quot;&gt;&lt;/script&gt;
&nbsp;
        <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
            $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">//this code will be added to the onclick event</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#save_user_button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//add the values we need for the API to an object</span>
                    <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//build the object</span>
                    data.<span style="color: #660066;">guid</span>                   <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#guid'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">defaultallocation</span>      <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#projecttype'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">email</span>                  <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">username</span>               <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#username'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">fullname</span>               <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fullname'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//turn the object in to a JSON string</span>
                    <span style="color: #003366; font-weight: bold;">var</span> myJson <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://testurl/service/user&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//call the post</span>
                    $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>jsonUser <span style="color: #339933;">:</span> myJson<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>myResult<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myResult<span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div&gt;
            &lt;table&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Project Type&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;projecttype&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;GUID&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;guid&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;User Name&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;username&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Full Name&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;fullname&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Email&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;email&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
            &lt;/table&gt;
&nbsp;
            &lt;input type=&quot;button&quot; id=&quot;save_user_button&quot; value=&quot;Save&quot;/&gt;
&nbsp;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slow and Locked MySQL Queries</title>
		<link>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/</link>
		<comments>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 17:08:59 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Science and Tech]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=498</guid>
		<description><![CDATA[One of our clients&#8217; servers recently saw a huge drop in speed. None of the hardware had been changed, and while the total number of users has been steadily increasing for the last few years, it has not seen any kind of spike that I thought might cause this type of problem. In order to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.getdowntonight.co.uk/wp-content/mysql2.png"><img class="alignright size-thumbnail wp-image-394 colorbox-498" title="mysql2" src="http://www.getdowntonight.co.uk/wp-content/mysql2-150x150.png" alt="" width="90" height="90" /></a>One of our clients&#8217; servers recently saw a huge drop in speed. None of the hardware had been changed, and while the total number of users has been steadily increasing for the last few years, it has not seen any kind of spike that I thought might cause this type of problem.</p>
<p>In order to try to find the fault or problem, I had to look in many different places and discovered a lot about Linux and MySQL. I enjoy these fact finding missions, even though there are always a lot of dead ends.</p>
<p>I thought I would use this blog as a place to write down all the areas that are worth checking, in case anyone else finds themselves in this situation.</p>
<p>Things to check:</p>
<ul>
<li>The Process List</li>
<li>MySQL Slow Query Log</li>
<li>Server free disk space</li>
<li>Server memory usage</li>
<li>Server load</li>
<li>Your queries</li>
<li>Your indexes</li>
</ul>
<p>Our server was running on Linux Centos 3, and many of the commands below are Linux only. For executing the MySQL commands and queries I suggest getting something like WebYog&#8217;s excellent<a href="http://www.webyog.com/en/downloads.php" target="_blank"> SQLYog</a>, or using MySQL&#8217;s own <a href="http://dev.mysql.com/downloads/workbench/5.2.html" target="_blank">MySQL Workbench</a>.</p>
<p><strong>Listing active MySQL queries<br />
</strong></p>
<p>MySQL contains the ability to show a list of currently running queries. From within MySQL &#8211; execute the following query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SHOW</span> PROCESSLIST<span style="color: #000033;">;</span></pre></div></div>

<p>This will show a list that details which users, hosts, databases are being used to execute queries &#8211; how long they have been going for, and what state they are in. Look for queries that have been running for a long time, or have the state of &#8216;locked&#8217;. For more information <a href="http://dev.mysql.com/doc/refman/5.5/en/show-processlist.html" target="_blank">see here</a>.</p>
<p><strong>Breaking down your queries</strong></p>
<p>It is crucial that you enable slow query logging and it is quite simple to set up. Edit your my.cnf file, and make sure the following is present:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 3</pre></div></div>

<p>(Adjust the log_query_time setting to suit the length of the query you are trying to detect)</p>
<p>Once this is in place, restart the MySQL server and start checking the new log file.</p>
<p>The MySQL command <a href="http://dev.mysql.com/doc/refman/5.1/en/using-explain.html" target="_blank">EXPLAIN</a> allows you to see a breakdown of the steps taken by MySQL to get your query results, including information about joins and the sequence of queries called. You can use the information it outputs to help optimise your own queries.</p>
<p>The utility is easy to use. Simply prefix your SELECT statement with the word EXPLAIN. eg.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">EXPLAIN</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> userName<span style="color: #000033;">,</span> firstName<span style="color: #000033;">,</span> lastName
<span style="color: #990099; font-weight: bold;">FROM</span> users
<span style="color: #990099; font-weight: bold;">WHERE</span> firstName <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">'da<span style="color: #008080; font-weight: bold;">%</span>'</span><span style="color: #000033;">;</span></pre></div></div>

<p><strong>top</strong><a href="http://www.getdowntonight.co.uk/wp-content/Screen-shot-2010-12-17-at-16.53.07.png"><img class="alignright size-thumbnail wp-image-499 colorbox-498" title="Output from the Linux top command" src="http://www.getdowntonight.co.uk/wp-content/Screen-shot-2010-12-17-at-16.53.07-150x150.png" alt="" width="150" height="150" /></a></p>
<p>This command shows you a list of applications and services running on the machine, along with some basic information about the resources they are using.</p>
<p>From here you can see the system load, free memory and the % of CPU for each process.</p>
<p>To quit and return to the shell, use CTRL+C.</p>
<p><strong>df -h</strong></p>
<p>This will show you how much free space is on your mounted drives, in human readable form.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">[sam@webserver1 /]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              9.8G  3.9G  5.9G  40% /
none                 1014M     0 1014M   0% /dev/shm
/dev/md2               57G   31G   27G  54% /disk1</pre></div></div>

<p><strong>tail</strong></p>
<p>This is a quick way of looking at the last few lines of a log file. The following will show you the last 10 lines of the mysql log.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">tail /var/log/mysql.log</pre></div></div>

<p>You can also specify that you want to view a specific number of lines by using the -n parameter. eg.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">tail -n 50 /var/log/mysql.log</pre></div></div>

<p>Eventually, after going through lots of checking and tests, we discovered that the server was simply at capacity. It hadn&#8217;t been upgraded for 8 years and the number of users had quadrupled during that time &#8211; with users from 2 other continents now logging on regularly. The database was on the same hardware as the web-server software and the system was just becoming overloaded.</p>
<p>We managed to speed things up considerably before we were forced to upgrade, mostly by examining the slow-query-log and adding indexes where appropriate. Also, many of our queries were refined and tidied up &#8211; so we were definitely not wasting our time running the examinations. It has made me realise that it is probably worth going back over old code every now and then to check for potential improvements &#8211; something we only tend to do if there is a client requirement, or an OS upgrade required.</p>
<p>We have now performed a complete upgrade to the latest hardware available, with 8GB of memory, more CPU cores than I suspect are really needed, the latest Centos 5 OS and all the most recent MySQL/Apache and PHP versions &#8211; which has made the system run incredibly quickly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the database from inside a helper (CodeIgniter)</title>
		<link>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/</link>
		<comments>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 09:06:17 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=468</guid>
		<description><![CDATA[I have some custom functions that I store in a helper in CodeIgniter. Some of those functions need to use the database, and to do so you have to explicitly tell the function to load the Code Igniter framework and database class. Its pretty simple when you know how, but it took quite a while [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright colorbox-468" title="CodeIgniter Logo" src="http://herloct.files.wordpress.com/2009/05/ci_logo_flame.jpg" alt="" width="90" height="98" />I have some custom functions that I store in a helper in CodeIgniter. </p>
<p>Some of those functions need to use the database, and to do so you have to explicitly tell the function to load the Code Igniter framework and database class.</p>
<p>Its pretty simple when you know how, but it took quite a while to work it out.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_user_full_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//the database functions can not be called from within the helper</span>
    <span style="color: #666666; font-style: italic;">//so we have to explicitly load the functions we need in to an object</span>
    <span style="color: #666666; font-style: italic;">//that I will call ci. then we use that to access the regular stuff.</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//select the required fields from the database</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstName, lastName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//tell the db class the criteria</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'userId'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//supply the table name and get the data</span>
    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//ensure that there is something in the variable - in case of no match</span>
    <span style="color: #000088;">$fullName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//get the full name by concatinating the first and last names</span>
        <span style="color: #000088;">$fullName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">firstName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastName</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// return the full name;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$fullName</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Eclipse as a PHP IDE in Ubuntu 9.10</title>
		<link>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 17:05:40 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=405</guid>
		<description><![CDATA[This is actually much easier than any of the guides I found online make out. Firstly, install Eclipse from the repositories. Then open it up, select your default workspace (if you havent already) and then: From the Help menu, select &#8220;Install new software&#8221;. Click the &#8220;Add&#8221; button and add the following: Name: Eclipse Updates (Galileo) [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright colorbox-405" src="http://wwwbruegge.informatik.tu-muenchen.de/twiki/pub/Lehrstuhl/SysiphusGoesEclipse/eclipse.png" alt="" width="90" height="90" />This is actually much easier than any of the guides I found online make out.</p>
<p>Firstly, install <strong>Eclipse</strong> from the repositories. Then open it up, select your default workspace (if you havent already) and then:</p>
<ol>
<li>From the Help menu, select &#8220;Install new software&#8221;.</li>
<li>Click the &#8220;Add&#8221; button and add the following:
<ol></ol>
<ul>
<li><strong>Name</strong>: Eclipse Updates (Galileo)</li>
<li><strong>Location</strong>: http://download.eclipse.org/releases/galileo/</li>
</ul>
<ol></ol>
</li>
<li>Apply your changes and wait for the contents to download.</li>
<li>When all is ready, select your new source from the drop down and look for the &#8220;Programming languages&#8221; section.</li>
<li>Open it up and add the &#8220;PHP Development Tools (PDT) SDK Feature&#8221;.</li>
<li>Step through using Next and Finish etc, and after a few moments downloading and installing you now have a PHP ready IDE.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Loading JSON data &#8211; the EASY way!</title>
		<link>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 12:22:04 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=398</guid>
		<description><![CDATA[A few weeks ago I wrote a blog post about using jQuery and JSON to automatically load data from a JSON file in to name-matched controls on an HTML page. It is only now that I realise quite how powerful this is! The great thing about it is that you do not have to edit [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-403 colorbox-398" title="json160" src="http://www.getdowntonight.co.uk/wp-content/json160.gif" alt="json160" width="96" height="96" />A few weeks ago I wrote a blog post about using jQuery and JSON to automatically load data from a JSON file in to name-matched controls on an HTML page.</p>
<p><strong>It is only now that I realise quite how powerful this is!</strong></p>
<p>The great thing about it is that you do not have to edit your data-load function if you add a new field to the database. Because the jQuery function loops through all the fields in the JSON data, it will automatically insert the values in to the correct fields, providing those fields are named the same as the html form controls.</p>
<p>Here is the code again for those who dont want to check back.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/yourJson.js, function(myJson){
	$.each(myJson.rows, function(i,item) {
		 for (prop in item) {
		 	 $('#' + prop).val(item[prop]);
		 }
	});
});</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing MyODBC 3.51 on Windows 7 x64</title>
		<link>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 11:11:44 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[64 bit]]></category>
		<category><![CDATA[connector]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[myodbc]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=393</guid>
		<description><![CDATA[In order to get some of our 32 bit applications working on Windows 7 64 bit edition, we need to provide support for the MySQL 3.51 ODBC connector. This is actually quite simple to do, as long as you know what to look for. The ODBC manager that you are able to access from within [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-394 colorbox-393" title="mysql2" src="http://www.getdowntonight.co.uk/wp-content/mysql2.png" alt="mysql2" width="105" height="105" />In order to get some of our 32 bit applications working on Windows 7 64 bit edition, we need to provide support for the <a href="http://dev.mysql.com/downloads/connector/odbc/3.51.html" target="_blank">MySQL 3.51 ODBC</a> connector.</p>
<p>This is actually quite simple to do, as long as you know what to look for. The ODBC manager that you are able to access from within Windows is not going to work for you, but it turns out that Microsoft provide a 32 bit manager that will.</p>
<p>To use this manager, run the following command:</p>
<p><strong>c:\windows\syswow64\odbcad32.exe</strong></p>
<p>Please note that it is not good enough to just type odbcad32.exe, as there is another file in the path with the same file name (great work MS!). However, once you have opened this application up, it works in the exact same way as if you were running XP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
	</channel>
</rss>

