<?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; linux</title>
	<atom:link href="http://www.clker.com/blog/category/linux/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>Linux average load</title>
		<link>http://www.clker.com/blog/2009/01/31/linux-average-load/</link>
		<comments>http://www.clker.com/blog/2009/01/31/linux-average-load/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 17:08:34 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/?p=182</guid>
		<description><![CDATA[It was the first time yesterday that I took sometime to understand what is the &#8220;average load&#8221; that appears with the top shell command. It turns out that it is a very informative number, if used right.
Linux averages the number of processes running, or can run &#8211; but may be blocked waiting for I/O. The [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.clker.com/clipart-23701.html" target="_blank"><img style="border:0px;margin:5px;float:left;" title="Motudo Powerlifting" src="http://www.clker.com/cliparts/c/0/b/6/12178614971385339408motudo_Powerlifting.svg.thumb.png" alt="" /></a>It was the first time yesterday that I took sometime to understand what is the &#8220;average load&#8221; that appears with the <strong>top </strong>shell command. It turns out that it is a very informative number, if used right.</p>
<p>Linux averages the number of processes running, or can run &#8211; but may be blocked waiting for I/O. The average is calculated three times: for a minute, 5 minutes and 15 minutes.</p>
<p>In case that no processes were blocked on I/O, this number should always be less than the number of available CPU cores. For insance, if the load average is 2.6 this means that in average 2.6 processes were running or wanted to run. If you have only two cores, this means that there&#8217;s in average 0.6 processes that cannot find an available CPU to run, which means that you need to upgrade your machine (or server).</p>
<p>Since this number grows when processes are blocked on I/O, it is nice to know whether there&#8217;s any blocked on I/O or not before going ahead and spending the last penny to buy new hardrware. The solution is a tool called <strong>atop</strong>. If the disks are stressed and cannot keep up with the requests (and consequently processes will be waiting for the disk) you will see the DSK line (or lines if you had more than one) in red.</p>
<p>At that point you should find who is the culprit, and do something to run that process in a better way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2009/01/31/linux-average-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discovering some of Linux Cow Powers: awk and bash</title>
		<link>http://www.clker.com/blog/2008/07/22/discovering-some-of-linux-cow-powers-awk-and-bash/</link>
		<comments>http://www.clker.com/blog/2008/07/22/discovering-some-of-linux-cow-powers-awk-and-bash/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 05:10:35 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[move]]></category>
		<category><![CDATA[mv]]></category>
		<category><![CDATA[rename]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/?p=114</guid>
		<description><![CDATA[If you&#8217;ve never used linux you should give it a try. The simplest way is to install colinux with xming. If you feel its involved, just burn an ubuntu 8.04 bootable cd. It works out of the CD with almost all the every day used features without installtion, formating or any other extra work.
One of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.clker.com/clipart-3716.html" target="_blank"><img style="border:0px;margin:5px;float:left;" title="Etiquette Icons" src="http://www.clker.com/cliparts/b/6/c/b/11949857311509536676gnome-terminal.svg.thumb.png" alt="" /></a>If you&#8217;ve never used linux you should give it a try. The simplest way is to install colinux with xming. If you feel its involved, just burn an ubuntu 8.04 bootable cd. It works out of the CD with almost all the every day used features without installtion, formating or any other extra work.</p>
<p>One of the cow powers that I use linux for, and didn&#8217;t find a way to do it using the windows shell is renaming a lot of files. I had around 3000 bmp files, their names were in the following format:</p>
<p>&lt;word&gt;-&lt;volume&gt;-&lt;number&gt;.bmp</p>
<p>and I wanted to rename them to</p>
<p>&lt;word&gt;-&lt;number&gt;.bmp</p>
<p>I couldn&#8217;t find a way to do this on windows except with writing a small pogram. On linux the solution is a program called <strong>awk</strong>, which can tokenize input strings, and write parts of them out. <strong>awk</strong> is a sophistiacated tool, and I usually use a very small subset of its features.</p>
<p>The solution was finally something similar to this:</p>
<pre>find .bmp | awk -F- '{print "mv "$0" "$1"-"$3;}' | bash -v</pre>
<p>The first part is running the find program to find all files with extension .bmp. The results are then piped as input to awk, instead of being written to the screen. <strong>awk</strong> is told that the field separator is &#8216;-&#8217; using the -F parameter. A one statement <strong>awk</strong> program says print the words <strong>mv</strong> to issue commands to rename a file, then <strong>$0</strong> for the full string before tokenizing, then the <strong>$1</strong> for the first tokenized part, and <strong>$3</strong> for the third tokenized part, skipping the second. So <strong>awk</strong> is being used to write the commands that we need to execute.</p>
<p>Those commands are then piped to <strong>bash</strong>, the bourne shell with the verbose flag on so that we can see the commands being executed.</p>
<p>A good practice when trying something like that is to pipe the results first to <strong>less</strong>, instead of <strong>bash</strong>. <strong>less</strong> is a program like <strong>more</strong>, which gives the user the ability to inspect whatever was piped to it and filp forward and backwords. It also includes some nice features like -N to show numbers, and searching for a word using the forward slash /  , with commands very similary to vim.</p>
<p>So the less version of the line whould be this:</p>
<pre>find .bmp | awk -F- '{print "mv "$0" "$1"-"$3;}' | less</pre>
<p>This is a very handy technique in renaming lots of files, or carrying batch operations on multiple files that I usually use.</p>
<p>Technorati Tags: <a href="#" rel="tag">linux</a>, <a href="#" rel="tag"> bash</a>, <a href="#" rel="tag"> find</a>, <a href="#" rel="tag"> awk</a>, <a href="#" rel="tag"> less</a>, <a href="#" rel="tag"> rename</a>, <a href="#" rel="tag"> move</a>, <a href="#" rel="tag"> mv</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/07/22/discovering-some-of-linux-cow-powers-awk-and-bash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GNUPlot wordpress plugin v1.1</title>
		<link>http://www.clker.com/blog/2008/07/18/gnuplot-wordpress-plugin-v11/</link>
		<comments>http://www.clker.com/blog/2008/07/18/gnuplot-wordpress-plugin-v11/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 21:11:43 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[GNUPlot plugin]]></category>
		<category><![CDATA[Internet general]]></category>
		<category><![CDATA[Internet programming]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/?p=101</guid>
		<description><![CDATA[<!--GNUPLOT code:

set size 1,0.7
set dummy u,v
unset key
set parametric
set view 60, 30, 1.1, 1.33
set isosamples 50, 20
set title "Interlocking Tori - PM3D surface with depth sorting"
set urange [ -3.14159 : 3.14159 ] noreverse nowriteback
set vrange [ -3.14159 : 3.14159 ] noreverse nowriteback
set pm3d depthorder
splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d,\
1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d

-->Plots GNUPlot charts without GNUPlot on your server. This plugin communicates with our custom version of GNUPlot hosted at clker.com, and responds with a PNG chart or errors in case of errors.
Write your GNUPlot code between [ gplot] and [ /gplot] (without spaces). Maximum chart size is 1&#215;1.
To install

Copy the file ( gnuplot plugin ) [...]]]></description>
			<content:encoded><![CDATA[<!--GNUPLOT code:

set size 1,0.7
set dummy u,v
unset key
set parametric
set view 60, 30, 1.1, 1.33
set isosamples 50, 20
set title "Interlocking Tori - PM3D surface with depth sorting"
set urange [ -3.14159 : 3.14159 ] noreverse nowriteback
set vrange [ -3.14159 : 3.14159 ] noreverse nowriteback
set pm3d depthorder
splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d,\
1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d

--><p>Plots GNUPlot charts without GNUPlot on your server. This plugin communicates with our custom version of GNUPlot hosted at clker.com, and responds with a PNG chart or errors in case of errors.</p>
<p>Write your GNUPlot code between [ gplot] and [ /gplot] (without spaces). Maximum chart size is 1&#215;1.</p>
<p>To install</p>
<ol>
<li>Copy the file ( <a href="http://www.clker.com/blog/wp-content/uploads/2008/07/gnuplot.phptxt">gnuplot plugin</a> ) in you wp-content/plugins directory, and rename to .php instead of .phptxt.</li>
<li>Create wp-content/cache directory, and make sure it is write able to the webserver</li>
<li>Activate the plugin from the plugins tab inside wordpress</li>
</ol>
<p>Example:</p>
<p>[ gplot]</p>
<pre>set size 1,0.7
set dummy u,v
unset key
set parametric
set view 60, 30, 1.1, 1.33
set isosamples 50, 20
set title "Interlocking Tori - PM3D surface with depth sorting"
set urange [ -3.14159 : 3.14159 ] noreverse nowriteback
set vrange [ -3.14159 : 3.14159 ] noreverse nowriteback
set pm3d depthorder
splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d,\
1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d</pre>
<p>[/ gplot]</p>
<p>would produce this:</p>
<p><center><a href='http://www.clker.com/blog/2008/07/16/gnuplot-wordpress-plugin/'><img src="http://www.clker.com/blog/wp-content/cache/plot_a56834641bf4085dfb2d89574ebdb210.png" style="border:none;"/></a></center></p>
<p>&#8230; Enjoy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/07/18/gnuplot-wordpress-plugin-v11/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>ionice and daily backups</title>
		<link>http://www.clker.com/blog/2008/06/25/ionice-and-daily-backups/</link>
		<comments>http://www.clker.com/blog/2008/06/25/ionice-and-daily-backups/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 06:28:34 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[ionice]]></category>
		<category><![CDATA[nice]]></category>
		<category><![CDATA[priority]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/?p=35</guid>
		<description><![CDATA[Anyone running a web server will either use a RAID for information protection, or will run a cron job that backups all the data daily
If you are running a budget server like mine, then most likely you&#8217;ll be doing daily backups. At 4 am everyday a backup process runs and stores a dump of the [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone running a web server will either use a RAID for information protection, or will run a cron job that backups all the data daily</p>
<p>If you are running a budget server like mine, then most likely you&#8217;ll be doing daily backups. At 4 am everyday a backup process runs and stores a dump of the SQL and gzip of all the web folders including the SVN repository on a separate harddrive, which gets unmounted after the backup is done. The process takes around 2 hours to complete, during which the hard drives are all stressed and if the backup scripts were not carefully written they will hog any apache request due to slow disk access.</p>
<p>Because the primary reason of a webserver is to serve pages, I do two things to guarantee that any apache or database process will take precedence in resources when compared to the backup process:<br />
1. The backup process runs with <strong>nice -n19 &lt;backup&gt;</strong>. This means that the process is running with a CPU idle priority, and will only use the CPU if no other process needs it. Using only <strong>nice</strong> will guarantee that the CPU is free, but programs like tar and gzip are big disk users and although they might not use a lot of CPU, a very small CPU usage is enough to generate big disk reads/writes. Large disk reads/writes usually will block other processes and keep them waiting for the disk resource, and will thus slow down apache, postgres and mysql and finally all pages accessed during the backup. In simple words, during backup if one tries to browse any of my websites when the backup process is only <strong>niced</strong>, the pages will load very slow.<br />
2. This leads us to the second precaution, <strong>ionice -c2 -n7</strong> nice -n19 &lt;backup&gt;. ionice is a tool that not so many people know that it exists. It basically prioritizes the disk access for different processes. Long tasks that access the disk a lot, and which are not that important or time critical should be given a lower priority compared to those that require fast turn around. ionice has three priority classes given by the parameter -c. Class 1 is idle priority, and only root can run processes in that class. Class 2 is best effort priority, within which there are 0-7 levels given by the -n parameter, 0 being highest priority and 7 being lowest. Class 3 is real time.</p>
<p>ionicing and nicing the backup process makes a huge difference in the speed and response of the webserver during the daily backup, especially if it was long. Try going over <a href="http://linux.die.net/man/1/ionice">its man page</a>. <a href="http://friedcpu.wordpress.com/2007/07/17/why-arent-you-using-ionice-yet/">A good post about ionice is here</a>.</p>
<p>Technorati Tags: <a href="#" rel="tag">ionice</a>, <a href="#" rel="tag"> nice</a>, <a href="#" rel="tag"> backup</a>, <a href="#" rel="tag"> disk</a>, <a href="#" rel="tag"> priority</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/06/25/ionice-and-daily-backups/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gatner &#8220;Windows is collapsing&#8221;</title>
		<link>http://www.clker.com/blog/2008/04/11/gatner-windows-is-collapsing/</link>
		<comments>http://www.clker.com/blog/2008/04/11/gatner-windows-is-collapsing/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 15:28:17 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[mac os]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[operating system]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[tivo]]></category>
		<category><![CDATA[vista]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows xp]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2008/04/11/gatner-windows-is-collapsing/</guid>
		<description><![CDATA[So Gartner, one of the largest analysis companies said in a conference that windows is collapsing. Lots of reasons were given including a large code for windows that became un-maintainable and lead Microsoft to start from a more stable release of Windows 2003, and improve on for Vista. This in turn lead to Vista not [...]]]></description>
			<content:encoded><![CDATA[<p>So Gartner, one of the largest analysis companies said in a conference that <a href="http://www.techcrunch.com/2008/04/11/gartner-says-vista-will-collapse-and-thats-why-the-yahoo-deal-must-happen/trackback/">windows is collapsing</a>. Lots of reasons were given including a large code for windows that became un-maintainable and lead Microsoft to start from a more stable release of Windows 2003, and improve on for Vista. This in turn lead to Vista not really delivering meaningful enhancements from the point of view of the end consumer. Also, the fact that applications now are moving on the web and becoming OS agnostic where you can run many available software almost on all operating systems (openoffice for example, inkscape and others based on GNU&#8217;s compilers or java).</p>
<p>Other reasons included a hardware demanding OS, which can&#8217;t fit on small PDA&#8217;s and thus giving the chance for Linux and OS X. I add to this list, the complete prevalence of Linux in embedded OSs in appliances like Tivos, with zero competition from Microsoft.</p>
<p>A big major contribution from my point of view is the reason of making a new release. When a company decides to allocate resources for the development of a software, they need goals. The only goal that is obvious from the release of Vista was to duress people into DRM, using windows position as a must be OS on every PC or  laptop. A very important lesson that you can&#8217;t force the whole world into only your own vision, but you have to embrace what people want, make it your vision and may be add more on the side. After all people are the consumer. Unfortunately, that was the second time Microsoft did that, after they already suffered losses on the server side and hosting.</p>
<p>However, I do disagree with Gartner on the result that Microsoft or windows will crash. I believe that <a href="http://ajaxian.com/archives/getting-feedback-to-the-ie-8-team">Microsoft is trying to embrace</a> <a href="http://www.redhatmagazine.com/2008/04/10/ooxml-approved-by-iso-what-next/trackback/">the standards</a> and work with others, it&#8217;s just they&#8217;re not doing enough and lots of people doubt their intentions. My view is Microsoft becoming more like SUN or IBM where they will have to work with people and provide solutions for the problems that people see using ways that the people want.</p>
<p>Technorati Tags: <a href="#" rel="tag">microsoft</a>, <a href="#" rel="tag"> windows</a>, <a href="#" rel="tag"> crash</a>, <a href="#" rel="tag"> linux</a>, <a href="#" rel="tag"> apple</a>, <a href="#" rel="tag"> mac os</a>, <a href="#" rel="tag"> os x</a>, <a href="#" rel="tag"> tivo</a>, <a href="#" rel="tag"> embedded</a>, <a href="#" rel="tag"> operating system</a>, <a href="#" rel="tag"> vista</a>, <a href="#" rel="tag"> windows xp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/04/11/gatner-windows-is-collapsing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a tar gz on the fly using PHP</title>
		<link>http://www.clker.com/blog/2008/03/27/creating-a-tar-gz-on-the-fly-using-php/</link>
		<comments>http://www.clker.com/blog/2008/03/27/creating-a-tar-gz-on-the-fly-using-php/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 17:41:53 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim</dc:creator>
				<category><![CDATA[Internet general]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[gz]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tar]]></category>

		<guid isPermaLink="false">http://www.clker.com/blog/2008/03/27/creating-a-tar-gz-on-the-fly-using-php/</guid>
		<description><![CDATA[A while ago, I thought about creating a tar.gz file for every download, so that if someone runs a search, he/she then can download all the images in the results. After a little bit of research, I found that PHP has a function for gzip. I also knew that the tar format just sticks files [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I thought about creating a tar.gz file for every download, so that if someone runs a search, he/she then can download all the images in the results. After a little bit of research, I found that PHP has a function for gzip. I also knew that the tar format just sticks files after one another, so if I can implement the tar format in PHP then I can gzip all images in the results.</p>
<p>I found <a href="http://www.koders.com/php/fidA384A1E097E7BEA8DB56698D0FE248C7E1D68DB4.aspx?s=smtp+server">this LGPL code</a> that implemented the tar format. I used it (and modified it a little bit) to produce the online tar.gz functions:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">// Computes the unsigned Checksum of a file&#8217;s header</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// to try to ensure valid file</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// PRIVATE ACCESS FUNCTION</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> __computeUnsignedChecksum<span class="br0">&#40;</span><span class="re0">$bytestring</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; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">0</span>; <span class="re0">$i</span>&lt;<span class="nu0">512</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$unsigned_chksum</span> += <a href="http://www.php.net/ord"><span class="kw3">ord</span></a><span class="br0">&#40;</span><span class="re0">$bytestring</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">0</span>; <span class="re0">$i</span>&lt;<span class="nu0">8</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$unsigned_chksum</span> -= <a href="http://www.php.net/ord"><span class="kw3">ord</span></a><span class="br0">&#40;</span><span class="re0">$bytestring</span><span class="br0">&#91;</span><span class="nu0">148</span> + <span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$unsigned_chksum</span> += <a href="http://www.php.net/ord"><span class="kw3">ord</span></a><span class="br0">&#40;</span><span class="st0">&quot; &quot;</span><span class="br0">&#41;</span> * <span class="nu0">8</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$unsigned_chksum</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="li2">
<div class="de2"><span class="co1">// Generates a TAR file from the processed data</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// PRIVATE ACCESS FUNCTION</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> tarSection<span class="br0">&#40;</span><span class="re0">$Name</span>, <span class="re0">$Data</span>, <span class="re0">$information</span>=<span class="kw2">NULL</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; <span class="co1">// Generate the TAR header for this file</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="re0">$Name</span>,<span class="nu0">100</span>,<a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="st0">&quot;777&quot;</span>,<span class="nu0">7</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><a href="http://www.php.net/decoct"><span class="kw3">decoct</span></a><span class="br0">&#40;</span><span class="re0">$information</span><span class="br0">&#91;</span><span class="st0">&quot;user_id&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>,<span class="nu0">7</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><a href="http://www.php.net/decoct"><span class="kw3">decoct</span></a><span class="br0">&#40;</span><span class="re0">$information</span><span class="br0">&#91;</span><span class="st0">&quot;group_id&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>,<span class="nu0">7</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><a href="http://www.php.net/decoct"><span class="kw3">decoct</span></a><span class="br0">&#40;</span><a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$Data</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,<span class="nu0">11</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><a href="http://www.php.net/decoct"><span class="kw3">decoct</span></a><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><span class="br0">&#41;</span>,<span class="nu0">11</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><span class="st0">&quot; &quot;</span>,<span class="nu0">8</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <span class="st0">&quot;0&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>,<span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="st0">&quot;ustar&quot;</span>,<span class="nu0">6</span>,<a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">32</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">32</span><span class="br0">&#41;</span> . <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="re0">$information</span><span class="br0">&#91;</span><span class="st0">&quot;user_name&quot;</span><span class="br0">&#93;</span>,<span class="nu0">32</span>,<a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="re0">$information</span><span class="br0">&#91;</span><span class="st0">&quot;group_name&quot;</span><span class="br0">&#93;</span>,<span class="nu0">32</span>,<a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>,<span class="nu0">8</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>,<span class="nu0">8</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>,<span class="nu0">155</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span> .= <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span><a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>,<span class="nu0">12</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Compute header checksum</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$checksum</span> = <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><a href="http://www.php.net/decoct"><span class="kw3">decoct</span></a><span class="br0">&#40;</span>__computeUnsignedChecksum<span class="br0">&#40;</span><span class="re0">$header</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,<span class="nu0">6</span>,<span class="st0">&quot;0&quot;</span>,STR_PAD_LEFT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">0</span>; <span class="re0">$i</span>&lt;<span class="nu0">6</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$header</span><span class="br0">&#91;</span><span class="br0">&#40;</span><span class="nu0">148</span> + <span class="re0">$i</span><span class="br0">&#41;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$checksum</span>,<span class="re0">$i</span>,<span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$header</span><span class="br0">&#91;</span><span class="nu0">154</span><span class="br0">&#93;</span> = <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$header</span><span class="br0">&#91;</span><span class="nu0">155</span><span class="br0">&#93;</span> = <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">32</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Pad file contents to byte count divisible by 512</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$file_contents</span> = <a href="http://www.php.net/str_pad"><span class="kw3">str_pad</span></a><span class="br0">&#40;</span><span class="re0">$Data</span>,<span class="br0">&#40;</span><a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$Data</span><span class="br0">&#41;</span> / <span class="nu0">512</span><span class="br0">&#41;</span> * <span class="nu0">512</span><span class="br0">&#41;</span>,<a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="co1">// Add new tar formatted data to tar file contents</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$tar_file</span> = <span class="re0">$header</span> . <span class="re0">$file_contents</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$tar_file</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> targz<span class="br0">&#40;</span><span class="re0">$Name</span>, <span class="re0">$Data</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; <span class="kw1">return</span> <a href="http://www.php.net/gzencode"><span class="kw3">gzencode</span></a><span class="br0">&#40;</span>tarSection<span class="br0">&#40;</span><span class="re0">$Name</span>,<span class="re0">$Data</span><span class="br0">&#41;</span>,<span class="nu0">9</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>To  use those functions all you have to do is send a header with the mime type for the tar gz ( application/x-gzi<span id="__firefox-findbar-search-id" style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit"></span>p ) using the php header function. To add a tar/gz section for a file, read the file in an array using filegetcontents and pass the filename and data to the targz function. Echo what is returned. That&#8217;s it!</p>
<p>So why is it not active on clker.com website? I actually tried it and found that compression consumes a lot of CPU. In the first 20 minute I had more than one hundred connections for different users downloading their results and the CPU was saturated. This basically left no CPU for searching. So use it carefully, and only if you really need that functionality.</p>
<p>Technorati Tags: <a href="#" rel="tag">tar</a>, <a href="#" rel="tag"> gz</a>, <a href="#" rel="tag"> compress</a>, <a href="#" rel="tag"> online</a>, <a href="#" rel="tag"> php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clker.com/blog/2008/03/27/creating-a-tar-gz-on-the-fly-using-php/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>
