<?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>Clker.com - weblog &#187; server</title>
	<atom:link href="http://www.clker.com/blog/tag/server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.clker.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 21 Nov 2009 03:49:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Caching SQL results with PHP</title>
		<link>http://www.clker.com/blog/2008/05/12/caching-sql-results-with-php/</link>
		<comments>http://www.clker.com/blog/2008/05/12/caching-sql-results-with-php/#comments</comments>
		<pubDate>Mon, 12 May 2008 15:54:36 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bench]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2008/05/12/caching-sql-results-with-php/</guid>
		<description><![CDATA[I&#8217;ve been looking around lately on the best way to cache SQL results in PHP. I found some interesting articles posted in lots of places, but I didn&#8217;t find any that exactly matches my needs. The problem I have on hand is basically the same every growing website faces: decreasing mean resource usage per page [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking around lately on the best way to cache SQL results in PHP. I found some interesting articles posted in lots of places, but I didn&#8217;t find any that exactly matches my needs. The problem I have on hand is basically the same every growing website faces: decreasing mean resource usage per page request.</p>
<p><strong>Now &#8211; this is my plan A </strong>to keep up with the website&#8217;s growth without a lot of hardware upgrades. There is a plan B, but I will keep that to a later post.<br />
<span id="more-29"></span><br />
Usually, the time consumed by executing the SQL statements is more than 80% of the whole script time. Reducing this time will significantly reduce the resource usage. CPU is not the bottle neck, usually SQL queries result in a significant disk access especially if there&#8217;s a lot of inserts/updates/deletes.</p>
<p>The easiest and best way I found is to use PHP&#8217;s serialize to store the SQL results. This requires that we fetch all the rows we&#8217;re dealing with. So the sequence of operations is to check the cache file, if expired or does not exist then fetch all the rows from the result set, serialize in one variable, write it to the cache file.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span> <span class="st0">&quot;utils.php&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$cache_prefix</span>=<span class="st0">&#8216;/tmp/clkercache/&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> cache_fetch<span class="br0">&#40;</span><span class="re0">$filename</span>, <span class="re0">$expiration</span>=<span class="nu0">3600</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cache_prefix</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$filename</span>=<span class="re0">$cache_prefix</span>.<span class="re0">$filename</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$filename</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/time"><span class="kw3">time</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>-<a href="http://www.php.net/filemtime"><span class="kw3">filemtime</span></a><span class="br0">&#40;</span><span class="re0">$filename</span><span class="br0">&#41;</span>&gt;<span class="re0">$expiration</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$data</span>=<a href="http://www.php.net/unserialize"><span class="kw3">unserialize</span></a><span class="br0">&#40;</span><a href="http://www.php.net/base64_decode"><span class="kw3">base64_decode</span></a><span class="br0">&#40;</span><a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$filename</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$data</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> cache_store<span class="br0">&#40;</span><span class="re0">$filename</span>,<span class="re0">$data</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cache_prefix</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$filename</span>=<span class="re0">$cache_prefix</span>.<span class="re0">$filename</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @mk_dir<span class="br0">&#40;</span><span class="re0">$filename</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw1">return</span> file_put_contents<span class="br0">&#40;</span><span class="re0">$filename</span>,<a href="http://www.php.net/base64_encode"><span class="kw3">base64_encode</span></a><span class="br0">&#40;</span><a href="http://www.php.net/serialize"><span class="kw3">serialize</span></a><span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>So the way to use the caching functions would be something similar to this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span> !<span class="br0">&#40;</span><span class="re0">$pictures</span>=cache_fetch<span class="br0">&#40;</span><span class="st0">&quot;mypictures.cache&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$res</span>=query<span class="br0">&#40;</span><span class="st0">&quot;select pictureid from pictures order by rating15days desc limit 100&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span>=fetch_array<span class="br0">&#40;</span><span class="re0">$res</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="re0">$pictures</span><span class="br0">&#91;</span><span class="br0">&#93;</span>=<span class="re0">$row</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; cache_store<span class="br0">&#40;</span><span class="st0">&quot;mypictures.cache&quot;</span>,<span class="re0">$pictures</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>So how to do that if you have multiple queries? The way I store my cache files is by giving them suffix or prefix names depending on what is being stores. For example a file that store the pictures that are related to a picture whose id is 1500 being displayed, will be called <strong>related-1500.cache</strong>. For more complicated cases like searches, I would use the md5sum of the request URI.</p>
<p>The results were good. Using apache bench I tested the homepage. Before any caching it used to support 3 pages per second. After caching the result was 35. I think in my current situation with my current traffic, this is a very good result.</p>
<p>One might think so what does it take to generate pages at a much higher rate &#8211; say 300, 400 or even a 1000 or more? Well, that&#8217;s my plan B, and I&#8217;ll discuss that in more detail in another post. This plan B will generate that much pages per second.</p>
<p>Technorati Tags: <a href="#" rel="tag">optimization</a>, <a href="#" rel="tag"> server</a>, <a href="#" rel="tag"> sql</a>, <a href="#" rel="tag"> php</a>, <a href="#" rel="tag"> apache</a>, <a href="#" rel="tag"> bench</a>, <a href="#" rel="tag"> cache</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/05/12/caching-sql-results-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running your server is easy, fun but involved</title>
		<link>http://www.clker.com/blog/2008/03/01/running-your-server-is-easy-fun-but-involved/</link>
		<comments>http://www.clker.com/blog/2008/03/01/running-your-server-is-easy-fun-but-involved/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 01:09:09 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[Internet general]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2008/03/01/running-your-server-is-easy-fun-but-involved/</guid>
		<description><![CDATA[I love using Linux to do my work. My best usage of Linux is my web server, although I recall I read once that Linus never intended for the kernel to be used as a server. He was more focused on using the kernel in desktops. I&#8217;ve been running my own web server for almost [...]]]></description>
			<content:encoded><![CDATA[<p>I love using Linux to do my work. My best usage of Linux is my web server, although I recall I read once that Linus never intended for the kernel to be used as a server. He was more focused on using the kernel in desktops. I&#8217;ve been running my own web server for almost a year now, which runs two websites mibrahim.net my real estate website, and clker.com a to be online clipart website &#8211; we&#8217;re halfway there.</p>
<p>The fun part is simply everything just works. You&#8217;ll have all the tools you need starting from database engines like postgres, mysql to scripting languages like php, ruby with different types of webservers apache, lighthttpd and others. All the tools you might think of are there and under your own hand. Building your own server is not expensive &#8211; around $100 will do it. You don&#8217;t need a super quad core machine to produce extremely fast websites, unless you are already getting more than 50 page requests per second and at that point you will need something faster.</p>
<p>The performance bottle neck is never the CPU, it&#8217;s the hard drives read or write speeds. You can improve on that using fake RAIDs. Almost all Linux distros offer fake RAIDs and that is the cheapest way to improve the read speed.</p>
<p>Setting up your server is not a hard process. The best distributions that I recommend are Debian and Ubuntu. The reason is the very large library of software that comes with each. I believe that now the full distribution has grown more than 11 CDs. I used to run Debian and switched to Ubuntu a year ago and the reason behind the switch is the faster updates I get from Ubuntu, which enables me to use more recent and updated versions of PHP and the database engines.</p>
<p>The easiest setup is using the Ubuntu server CD, which is not any different from the desktop CD in terms of binaries. The only difference is that it won&#8217;t install the X11-server (GUI) and the window managers (gnome or kde) and the install program itself runs over the console and not VGA graphics. I use the server installation, and connect to my server using ssh. I have another old machine that runs Ubutu as well, and is used to run freenx. By that way I keep the server&#8217;s memory for the services running, and I can add all the GUI programs I want on this old machine.</p>
<p>Since I greatly benefited from running my own web server, I will share my experiences every now and then when I&#8217;ve got time to write.</p>
<p>Technorati Tags: <a href="#" rel="tag">ubuntu</a>, <a href="#" rel="tag"> linux</a>, <a href="#" rel="tag"> server</a>, <a href="#" rel="tag"> apache</a>, <a href="#" rel="tag"> database</a>, <a href="#" rel="tag"> sql server</a>, <a href="#" rel="tag"> database server</a>, <a href="#" rel="tag"> web server</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/03/01/running-your-server-is-easy-fun-but-involved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardware problems &#8211; the mystery solved</title>
		<link>http://www.clker.com/blog/2007/12/11/hardware-problems-the-mystery-solved/</link>
		<comments>http://www.clker.com/blog/2007/12/11/hardware-problems-the-mystery-solved/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 18:34:54 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AMD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[sempron]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[shutting down]]></category>
		<category><![CDATA[temperature]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2007/12/11/hardware-problems-the-mystery-solved/</guid>
		<description><![CDATA[I previously wrote about hardware problems that were puzzling me, and I finally found the answer. I installed sensors on ubuntu and ran ksensors and just watched what&#8217;s going on. The old server that was shutting down suddenly had an opteron dual core processor, which ran at 50 degrees Celsius at no load. I had [...]]]></description>
			<content:encoded><![CDATA[<p>I previously wrote about <a href="http://www.clker.com/blog/2007/12/08/hardware-problems/">hardware problems</a> that were puzzling me, and I finally found the answer. I installed sensors on ubuntu and ran ksensors and just watched what&#8217;s going on. The old server that was shutting down suddenly had an opteron dual core processor, which ran at 50 degrees Celsius at no load. I had three websites running there, the most recent addition is clker.com . Due to the large number of people that were trying to access the website, the CPU was loaded and overheated, which inturn lead to it shutting down.</p>
<p>Of course the solution is to put the server in a very cold room, which I don&#8217;t have. I resorted to buying a new board and CPU, which does not heat as much as the old ones and transfered the database and pictures to it. Currently the no load temperature is 11 degrees, which I think is great. This new board is a special sale from microcenter, both the board and CPU were for $94 with $15 rebate Sempron 64! I added 1GB of RAM. It really worked much better than my expectations, as I had very very low performance expectations from that CPU</p>
<p>Currently this server is running clker.com only, and will run mibrahim.net today. The CPU load as shown in top does not pass 2% except in spikes. People are still digging as well as search engine robots. So that&#8217;s a good value if someone wants to run his/her own starter website.</p>
<p>Technorati Tags: <a href="#" rel="tag">ubuntu</a>, <a href="#" rel="tag"> shutting down</a>, <a href="#" rel="tag"> temperature</a>, <a href="#" rel="tag"> sempron</a>, <a href="#" rel="tag"> AMD</a>, <a href="#" rel="tag"> performance</a>, <a href="#" rel="tag"> linux</a>, <a href="#" rel="tag"> web server</a>, <a href="#" rel="tag"> server</a>, <a href="#" rel="tag"> php</a>, <a href="#" rel="tag"> postgresql</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2007/12/11/hardware-problems-the-mystery-solved/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powered by Ubuntu</title>
		<link>http://www.clker.com/blog/2007/11/21/powered-by-ubuntu/</link>
		<comments>http://www.clker.com/blog/2007/11/21/powered-by-ubuntu/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 22:49:56 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[clker.com]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[powered]]></category>
		<category><![CDATA[powered by ubuntu]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2007/11/21/powered-by-ubuntu/</guid>
		<description><![CDATA[One of the SVG pictures that had troubles is the powered by Ubuntu logo. In an earlier post I described that I&#8217;m doing some SVG cleanup, and still to expect more cleanup in the future. One of the images that I was looking forward to is the powered by Ubuntu logo. So I&#8217;m up to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.clker.com/clipart-8361.html" target="_blank"><img style="border:0px;margin:5px;float:left;" title="Part of the Flat Icon Collection (Wed Aug 25 23:31:03 2004)" src="http://www.clker.com/cliparts/6/7/1/1/1194997941724293171linux_hdd_mount.svg.thumb.png" alt="" /></a>One of the SVG pictures that had troubles is the powered by Ubuntu logo. <a href="http://www.clker.com/blog/2007/11/21/clipart-cleanup/">In an earlier post</a> I described that I&#8217;m doing some SVG cleanup, and still to expect more cleanup in the future. One of the images that I was looking forward to is the <em>powered by <a href="http://www.ubuntu.com">Ubuntu</a></em> logo. So I&#8217;m up to some coloring for this night ! I will try to make a unified theme for both the website part, and the wordpress weblog part, and of course will incorporate the <a href="http://ubuntu.wordpress.com/2006/08/12/free-powered-by-ubuntu-stickers/">powered by Ubuntu logo</a>, since this server is actually powered by Ubuntu.</p>
<p>Technorati Tags: <a href="#" rel="tag">ubuntu</a>, <a href="#" rel="tag"> powered</a>, <a href="#" rel="tag"> powered by ubuntu</a>, <a href="#" rel="tag"> server</a>, <a href="#" rel="tag"> webserver</a>, <a href="#" rel="tag"> apache</a>, <a href="#" rel="tag"> wordpress</a>, <a href="#" rel="tag"> theme</a>, <a href="#" rel="tag"> css</a>, <a href="#" rel="tag"> style</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2007/11/21/powered-by-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
