<?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>Think Lamp &#187; PHP</title>
	<atom:link href="http://www.think-lamp.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.think-lamp.com</link>
	<description>Everything Linux Apache Php Mysql</description>
	<lastBuildDate>Sun, 05 Sep 2010 00:50:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Fastest Insertion Sort in PHP</title>
		<link>http://www.think-lamp.com/2009/08/fastest-insertion-sort-in-php/</link>
		<comments>http://www.think-lamp.com/2009/08/fastest-insertion-sort-in-php/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 20:20:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[analysis of algorithms]]></category>
		<category><![CDATA[insertion sort]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=189</guid>
		<description><![CDATA[$numbers = array(2,3,4,5,1,8,11,0); $count = count($numbers); for($i=1;$i&#60;$count;$i++){ $j=$i-1; $key = $numbers[$i]; while($j&#62;=0 &#38;&#38; $numbers[$j] &#62; $key){ $numbers[$j+1] = $numbers[$j]; $numbers[$j]= $key; $j= $j-1; } } print_r($numbers);]]></description>
			<content:encoded><![CDATA[<pre class="brush: php;">
$numbers = array(2,3,4,5,1,8,11,0);
$count = count($numbers);

for($i=1;$i&lt;$count;$i++){
	$j=$i-1;
	$key = $numbers[$i];
	while($j&gt;=0 &amp;&amp; $numbers[$j] &gt;  $key){
		$numbers[$j+1] = $numbers[$j];
		$numbers[$j]= $key;
		$j= $j-1;
	}
}
print_r($numbers);
</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2009%2F08%2Ffastest-insertion-sort-in-php%2F&amp;linkname=Fastest%20Insertion%20Sort%20in%20PHP"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2009/08/fastest-insertion-sort-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Principles of the PHP Masters</title>
		<link>http://www.think-lamp.com/2008/09/10-principles-of-the-php-masters/</link>
		<comments>http://www.think-lamp.com/2008/09/10-principles-of-the-php-masters/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 22:41:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[masters]]></category>
		<category><![CDATA[rules of php]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=56</guid>
		<description><![CDATA[With PHP&#8217;s widespread adoption,it&#8217;s almost too easy to find a script or snippet to do exactly what you need. Unfortunately, there&#8217;s no filter as to what is a &#8220;good practice&#8221; and what&#8217;s, well&#8230; not so good when writing a PHP script. We need trustworthy sources, who have proven they have a solid grasp on the [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #0000ff;"><strong><em>With PHP&#8217;s widespread adoption,it&#8217;s almost too easy to find a script or snippet to do <em>exactly</em> what you need. Unfortunately, there&#8217;s no filter as to what is a &#8220;good practice&#8221; and what&#8217;s, well&#8230; not so good when writing a PHP script. We need trustworthy sources, who have proven they have a solid grasp on the best practices of PHP.</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>We need PHP masters to show us the best principles to follow for high-grade PHP programming.</em></strong></span></p>
<p><span id="more-56"></span></p>
<h3><span style="color: #0000ff;"><br />
</span></h3>
<h3><span style="color: #0000ff;">1. Use PHP Only When You Need it &#8211; Rasmus Lerdorf</span></h3>
<p><span style="color: #0000ff;">There&#8217;s no better resource than PHP&#8217;s creator for knowing what PHP is capable of. Rasmus Lerdorf created PHP in 1995, and since then the language has spread like wildfire through the developer community, changing the face of the Internet. However, <a href="http://www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html">Rasmus didn&#8217;t create PHP with that intent</a>. <strong>PHP was created out of a need to solve web development problems</strong>.</span></p>
<blockquote><p><span style="color: #0000ff;">And as with many open source projects that have gone on to become popular, the motivation was never philosophical or even narcissistic. It was purely a case of needing a tool to solve real-world Web-related problems. In 1994 the options were fairly limited when it came to Web development tools.</span></p></blockquote>
<p><span style="color: #0000ff;">However, you can&#8217;t use PHP for everything. Lerdorf is the first to admit that PHP is really just a tool in your toolbox, and that even PHP has limitations.</span></p>
<blockquote><p><span style="color: #0000ff;">Use the right tool for the job. I have run across companies that have completely bought into PHP, deploying it absolutely everywhere, but it was never meant to be a general-purpose language appropriate for every problem. It is most at home as the front-end scripting language for the Web.</span></p></blockquote>
<p><span style="color: #0000ff;">Trying to use PHP for everything isn&#8217;t efficient, and it certainly isn&#8217;t the best use of your time as a web developer. Don&#8217;t be afraid to to use other languages if PHP isn&#8217;t working out for your project.</span></p>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-in;" src="http://eric.bachard.free.fr/mac/aquavcl/screenshots/july2007/we_need_you/20041021_laMouette-WeNeedYou.png" alt="http://eric.bachard.free.fr/mac/aquavcl/screenshots/july2007/we_need_you/20041021_laMouette-WeNeedYou.png" width="349" height="349" /></div>
<h3><span style="color: #0000ff;">2. Use Many Tables With PHP and MYSQL for Scalability &#8211; Matt Mullenweg</span></h3>
<p><span style="color: #0000ff;">Nobody needs to question Matt Mullenweg&#8217;s authority with PHP. He has, (alongside a rabid community), developed the most popular blogging system on the planet: <a title="Wordpress" href="http://wordpress.org/">WordPress</a>. After creating WordPress, Matt and company launched the stellar <a href="http://www.wordpress.com/">WordPress.com</a>, a free blogging site based on the <a href="http://mu.wordpress.org/">WordPress MU</a> code base blogging software for multiple blogs. At the time of this writing, WordPress.com hosts over 4 million blogs, and their users have written over 140,000 posts today. (You can see more interesting stats about WordPress.com usage <a title="wp stats" href="http://wordpress.com/stats/">here</a>.)</span></p>
<p><span style="color: #0000ff;">If anybody knows how to scale a website, it&#8217;s  Matt Mullenweg. In 2006 <a href="http://ma.tt/2006/03/wordpress-and-lyceum/">Matt gave some insight into WordPress&#8217; database structure</a> and explained why WordPress MU uses a separate MySQL table for each blog, as opposed to using one giant &#8220;monolithic&#8221; table for all of the blogs.</span></p>
<blockquote><p><span style="color: #0000ff;">We tested this approach for MU, but found it was too expensive to scale past a certain point. With monolithic structures you hit a wall based on your hardware. In MU users are divided and can be partitioned easily, for example on WordPress.com we have the users partitioned between 4096 databases, which allows you to scale very cheaply and efficiently to hundreds of thousands and even millions of users and extremely high levels of traffic.</span></p></blockquote>
<p><span style="color: #0000ff;">Being able migrate the tables allows the code and ultimately the blogs to run much faster and scale easier. Alongside some heavy caching, and smart database usage, Matt has shown that extremely popular sites like <a href="http://facebook.com/">Facebook</a> and WordPress.com can run off of PHP and handle the incredible traffic load.</span></p>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-in;" src="http://www.databasejournal.com/img/BS_bbdbAccess.gif" alt="http://www.databasejournal.com/img/BS_bbdbAccess.gif" width="480" height="216" /></div>
<h3><span style="color: #0000ff;">3. Never, ever trust your users &#8211; Dave Child</span></h3>
<p><span style="color: #0000ff;">Dave Child is the brainchild (teehee) behind the recently renamed <a href="http://www.addedbytes.com/">Added Bytes</a> (previously ilovejackdaniels.com) website that featured Dave&#8217;s excellent <a href="http://www.addedbytes.com/cheat-sheets/">cheat sheets for many programming languages</a>. Dave&#8217;s worked for many development companies in the UK and has established himself as an authority in the programming world.</span></p>
<p><span style="color: #0000ff;">Dave offers some sage advice when it comes to <a href="http://www.addedbytes.com/php/writing-secure-php/">writing secure code in PHP</a>: Don&#8217;t trust your users. They just might hurt you.</span></p>
<blockquote><p><span style="color: #0000ff;">So the cardinal rule of all web development, and I can&#8217;t stress it enough, is: Never, Ever, Trust Your Users. Assume every single piece of data your site collects from a user contains malicious code. Always. That includes data you think you have checked with client-side validation, for example using JavaScript. If you can manage that, you&#8217;ll be off to a good start. If PHP security is important to you, this single point is the most important to learn.</span></p></blockquote>
<p><span style="color: #0000ff;">Dave goes on to give specific examples of secure practices in parts <a href="http://www.addedbytes.com/php/writing-secure-php/">one</a>, <a href="http://www.addedbytes.com/php/writing-secure-php-2/">two</a> and <a href="http://www.addedbytes.com/php/writing-secure-php-3/">three</a> of his &#8216;Writing Secure PHP&#8217; series. But his ultimate takeaway is this:</span></p>
<blockquote><p><span style="color: #0000ff;"><strong>Finally, be completely and utterly paranoid</strong>. If you assume your site will never come under attack, or face any problems of any sort, then when something eventually does go wrong, you will be in massive amounts of trouble. If, on the other hand, you assume every single visitor to your site is out to get you and you are permanently at war, you will help yourself to keep your site secure, and be prepared in case things should go wrong.</span></p></blockquote>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-in;" src="http://i163.photobucket.com/albums/t316/chris-bauer/i_trust_you_to_kill_me_larg.jpg" alt="http://i163.photobucket.com/albums/t316/chris-bauer/i_trust_you_to_kill_me_larg.jpg" width="281" height="417" /></div>
<h3><span style="color: #0000ff;">4. Invest in PHP Caching &#8211; Ben Balbo</span></h3>
<p><span style="color: #0000ff;">Ben Balbo has been writing for <a href="http://www.sitepoint.com/">Site Point</a>, a very well respected tutorial site for the likes of developers and designers. He&#8217;s on the committee for both the Melbourne PHP User Group and Open Source Developers&#8217; Club, so he knows a thing or two about the language. It&#8217;s no surprise with Ben&#8217;s background as a PHP developer and trainer that he recommends putting a little more thought and preparation into <a href="http://www.sitepoint.com/article/caching-php-performance/">PHP caching</a>.</span></p>
<blockquote><p><span style="color: #0000ff;">If you have a busy and predominantly static web site&#8211;such as a blog&#8211;that&#8217;s managed through a content management system, it will likely require little alteration, yet may benefit from huge performance improvements resulting from a small investment of your time. Setting up caching for a more complex site that generates content on a per-user basis, such as a portal or shopping cart system, will prove a little more tricky and time consuming, but the benefits are still clear.</span></p></blockquote>
<p><span style="color: #0000ff;">There are many different techniques for caching in PHP, and Ben touches on a few of the bigger ones in the article, like:</span></p>
<ul>
<li><span style="color: #0000ff;">cached function calls</span></li>
<li><span style="color: #0000ff;">setting expiry headers</span></li>
<li><span style="color: #0000ff;">caching file downloads in IE</span></li>
<li><span style="color: #0000ff;">template caching</span></li>
<li><span style="color: #0000ff;">Cache_Lite</span></li>
</ul>
<p><span style="color: #0000ff;">and many others. Because of the nature of dynamic languages like PHP, caching is critical to store those parts of the page that are accessed frequently and don&#8217;t change often.</span></p>
<div class="tutorial_image" style="text-align: center;"><img src="http://www.planetoftunes.com/computer/c_media/caching.gif" alt="http://www.planetoftunes.com/computer/c_media/caching.gif" /></div>
<h3><span style="color: #0000ff;">5. Speed up PHP Development with an IDE, Templates and Snippets &#8211; Chad Kieffer</span></h3>
<p><span style="color: #0000ff;">When Chad Kieffer isn&#8217;t busy rocking user interfaces and administering databases, he&#8217;s giving expertise advice from his blog <a href="http://2tbsp.com/">2 tablespoons</a>. Because of Chad&#8217;s <a href="http://www.linkedin.com/in/chadkieffer">wide field of expertise</a>, he&#8217;s often able to see the big picture that other programmers might not, specifically when it comes to the holistic approach that Chad takes to developing a website. He specializes in all aspects of the development process, so any insights he can provide with putting together an entire project is going to be useful.</span></p>
<p><span style="color: #0000ff;">Chad believes that using an IDE like <a href="http://www.eclipse.org/pdt/">Eclipse PDT</a> (Eclipse&#8217;s PHP development package) with a mixture of templates and snippets can really speed up the turnaround time on a project.</span></p>
<blockquote><p><span style="color: #0000ff;">Busy schedules, long to do lists, and deadlines make it tough for developers to get familiar with some of the advanced features their tools provide. This is a shame, because some features, like Eclipse Templates, can really reduce coding time and errors.</span></p></blockquote>
<p><span style="color: #0000ff;">Common sense says that any time you can automate a task, the quicker you&#8217;ll get the project done. The same holds true with Dan&#8217;s theory. By taking the time to create templates that you&#8217;ll use over and over, you&#8217;ll save tons of time automating the repetitive parts of coding.</span></p>
<p><span style="color: #0000ff;">By using an IDE like Eclipse and the PDT package, you&#8217;ll find that your development time will incrementally speed up. The IDE will auto-close brackets, add those missing semicolons and even allow you to debug within the editor, without having to upload to the server. (Chad has a nifty tutorial on <a href="http://2tbsp.com/content/getting_started_eclipse_php_development_tools_%28pdt%29">getting started with Eclipse PDT</a> and the benefits of an IDE in general, if you&#8217;re interested.)</span></p>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-in;" src="http://blog.xole.net/resources/zend-studio-beta-5.0.png" alt="http://blog.xole.net/resources/zend-studio-beta-5.0.png" width="338" height="253" /></div>
<h3><span style="color: #0000ff;">6. Make Better Use of PHP&#8217;s Filter Functions &#8211; Joey Sochacki</span></h3>
<p><span style="color: #0000ff;">While Joey Sochacki may not be as big of a name as Matt Mullenweg in the PHP community, he&#8217;s a seasoned web developer and shares tips that he&#8217;s picked up along the way at his blog <a href="http://devolio.com/blog">Devolio</a>.</span></p>
<p><span style="color: #0000ff;">Joey <a href="http://devolio.com/blog/archives/413-Data-Filtering-Using-PHPs-Filter-Functions-Part-one.html">has found</a> that even though there is a ton of filtering that has to happen when writing PHP code, not many programmers make use of PHP&#8217;s filter functions.</span></p>
<blockquote><p><span style="color: #0000ff;">Filtering data. We all have to do it. Most, if not all of us, despise doing it. However, unbeknown to most are PHP&#8217;s filter_* functions, that allow us to do all sorts of filtering and validation. Using PHP&#8217;s filter_* functions, we can validate and sanitize data types, URLs, e-mail addresses, IP addresses, strip bad characters, and more, all with relative ease.</span></p></blockquote>
<p><span style="color: #0000ff;">Filtering can be tricky, but this guide can help immensely. With Joey&#8217;s help you&#8217;ll learn how to install the filters and and filter nearly <em>anything</em>, taking advantage of the filtering power of PHP.</span></p>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-in;" src="http://www.potterswithoutborders.com/komasket/cartoon.jpg" alt="http://www.potterswithoutborders.com/komasket/cartoon.jpg" width="254" height="337" /></div>
<h3><span style="color: #0000ff;">7. Use a PHP Framework &#8211; Josh Sharp</span></h3>
<p><span style="color: #0000ff;">There has always been a debate as to whether to use a PHP framework like <a href="http://framework.zend.com/">Zend</a>, <a href="http://cakephp.org/">CakePHP</a>, <a href="http://codeigniter.com/">Code Igniter</a>, or <a href="http://en.wikipedia.org/wiki/PHP_frameworks#PHP">any other framework</a>. There are upsides and downsides to using one, and many developers have their own opinions about whether or not to go down this road.</span></p>
<p><span style="color: #0000ff;"><a href="http://www.joshsharp.com.au/portfolio/">Josh Sharp</a> is a web developer who makes his bread and butter creating websites for clients. This is why you should trust him when he says it&#8217;s a good idea to <a href="http://www.joshsharp.com.au/blog/view/why_you_should_be_using_a_framework">use a PHP framework</a> to save time and eliminate mistakes when programming. Why? Josh believes it&#8217;s because PHP is too easy to learn.</span></p>
<blockquote><p><span style="color: #0000ff;">But PHP&#8217;s ease of use is also its downfall. Because there are less restrictions on the structure of the code you write, it&#8217;s much easier to write bad code. But there is a solution: use a framework.</span></p></blockquote>
<p><span style="color: #0000ff;">PHP frameworks help standardize how you program, and can save lots of time in the development process. You can read more about the <a href="http://www.joshsharp.com.au/blog/view/why_you_should_be_using_a_framework">benefit of using a PHP framework</a> at Josh&#8217;s blog.</span></p>
<div class="tutorial_image" style="text-align: center;"><img src="http://www.webdevelopment2.com/wp-content/uploads/what-do-you-look-for-in-a-php-framework-graph.png" alt="http://www.webdevelopment2.com/wp-content/uploads/what-do-you-look-for-in-a-php-framework-graph.png" width="406" height="312" /></div>
<h3><span style="color: #0000ff;">8. Don&#8217;t use a PHP Framework &#8211; Rasmus Lerdorf</span></h3>
<p><span style="color: #0000ff;">Contrary to Josh&#8217;s belief that one should use a PHP framework, Rasmus Lerdorf, the Godfather of PHP himself, believes that frameworks aren&#8217;t that great. Why? Because they perform much slower than simple PHP.</span></p>
<p><span style="color: #0000ff;">During Rasmus&#8217; presentation at <a href="http://szeged2008.drupalcon.org/">Drupalcon 2008</a>, Rasmus compared the response times to a PHP page with a simple &#8220;Hello World&#8221; example, and compared it to a few PHP frameworks (<a href="http://talks.php.net/show/drupal08/24">slides 24-32</a>), and showed that PHP frameworks are much slower than straight PHP.</span></p>
<p><span style="color: #0000ff;">You can listen or watch the <a href="http://szeged2008.drupalcon.org/program/sessions/rasmus-lerdorf-keynote-simple-hard">entire presentation</a> where Rasmus shows the performance losses with PHP frameworks. In short, Rasmus shows that performance takes a major hit when you use a PHP framework as opposed to using pure PHP.</span></p>
<p><span style="color: #0000ff;">[<em>Note: If you have to use a PHP framework, Rasmus likes <a title="code ignitor" href="http://codeigniter.com/">Code Igniter</a> the best, as it is "least like a framework"</em>]</span></p>
<p style="text-align: center;"><img src="http://www.fmft.net/EU%20Constitution%20EU%20Treaty%20Referendum%20Mr%20Free%20Market%20I%20Say%20No%20Free%20Market%20Fairy%20Tales.JPG" alt="http://www.fmft.net/EU%20Constitution%20EU%20Treaty%20Referendum%20Mr%20Free%20Market%20I%20Say%20No%20Free%20Market%20Fairy%20Tales.JPG" width="333" height="317" /></p>
<h3><span style="color: #0000ff;">9. Use Batch Processing &#8211; Jack D. Herrington</span></h3>
<p><span style="color: #0000ff;">Jack Herrington is no stranger to PHP and the development world. On top of writing over 30 articles for the prestigious <a href="http://www.ibm.com/developerworks/">IBM developerWorks</a>, Jack has also published programming books like <a href="http://www.amazon.com/PHP-Hacks-Creating-Dynamic-Websites/dp/0596101392">PHP Hacks</a>. Jack is a bona fide <em>expert</em>.</span></p>
<p><span style="color: #0000ff;">Herrington recommends using <a href="http://www.ibm.com/developerworks/opensource/library/os-php-batch/">batch processing and cron</a> to tackle those tasks that can process in the background. Web users don&#8217;t want to wait long for tasks to complete on the web. There are some jobs that take longer that are much more suited to being done in the background.</span></p>
<blockquote><p><span style="color: #0000ff;">Certainly, in some small cases, it&#8217;s a bit easier to fire off of a helper thread to handle small jobs. But it&#8217;s easy to see that with the use of conventional tools &#8212; cron, MySQL, standard object-oriented PHP, and Pear::DB &#8212; creating batch jobs in PHP applications is easy to do, easy to deploy, and easy to maintain.</span></p></blockquote>
<p><span style="color: #0000ff;">Jack believes in simplicity, and instead of using threading on servers, he uses the simple combination of cron, PHP and MySQL to process tasks in the background.</span></p>
<blockquote><p><span style="color: #0000ff;">I&#8217;ve done both, and I think cron has the advantage of the &#8220;Keep It Simple, Stupid&#8221; (KISS) principle. It keeps the background processing simple. Instead of having a multithreaded job-processing application that runs forever and, thus, can never leak memory, you have a simple batch script that cron starts. The script determines whether there&#8217;s anything to do, does it, then exits. No need to worry about memory leaks. No need to worry about a thread stalling or getting caught in an infinite loop.</span></p></blockquote>
<div class="tutorial_image" style="text-align: center;"><img style="cursor: -moz-zoom-out;" src="http://publib.boulder.ibm.com/infocenter/zoslnctr/v1r7/topic/com.ibm.zconcepts.doc/zOSB003-0.gif" alt="http://publib.boulder.ibm.com/infocenter/zoslnctr/v1r7/topic/com.ibm.zconcepts.doc/zOSB003-0.gif" width="423" height="385" /></div>
<h3><span style="color: #0000ff;">10. Turn on Error Reporting Immediately &#8211; David Cummings</span></h3>
<p><span style="color: #0000ff;">David Cummings runs his own <a href="http://www.hannonhill.com/">software company</a> that specializes in content management systems, and has <a href="http://www.hannonhill.com/news/awards.html">won several awards</a>. If anyone knows how to develop a PHP application efficiently, it&#8217;s Dave.</span></p>
<p><span style="color: #0000ff;">David wrote in a SitePoint article about the <a href="http://www.sitepoint.com/article/quick-php-tips/">two PHP tips he wished he&#8217;d learned in the beginning</a>. One of the tips: Turn on error reporting immediately. It&#8217;ll save a great deal of time in the long run.</span></p>
<blockquote><p><span style="color: #0000ff;">The single most important thing I tell people who use PHP is to turn error reporting to its maximum level. Why would I want to do this? Generally the error reporting is set at a level that will hide many little things like:</span></p>
<ul>
<li><span style="color: #0000ff;">declaring a variable ahead of time,</span></li>
<li><span style="color: #0000ff;">referencing a variable that isn&#8217;t available in that segment of code, or</span></li>
<li><span style="color: #0000ff;">using a define that isn&#8217;t set.</span></li>
<p><span style="color: #0000ff;">These factors might not seem like that big a deal &#8212; until you develop structured or object oriented programs with functions and classes. Too often, writing code without error reporting turned up high would cost you hours as you scoured long functions that didn&#8217;t work because a variable was misspelled or not accessible.</span></ul>
</blockquote>
<p><span style="color: #0000ff;">Error reporting can make finding the reason for an error much easier. A tiny bug in the code can be quickly identified if PHP&#8217;s error reporting is turned on high. Save yourself some time and hair pulling by letting PHP find your bugs for you.</span></p>
<p style="text-align: center;"><img class="aligncenter" src="http://daringfireball.net/misc/2003/12/php_error_75.png" alt="http://daringfireball.net/misc/2003/12/php_error_75.png" width="440" height="131" /></p>
<p style="text-align: center;">-Insipred from <a href="http://nettuts.com/author/glen-stansberry/">Glen Stansberry</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F09%2F10-principles-of-the-php-masters%2F&amp;linkname=10%20Principles%20of%20the%20PHP%20Masters"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2008/09/10-principles-of-the-php-masters/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sieve of Eratosthenes in PhP</title>
		<link>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/</link>
		<comments>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 03:26:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[big o notation]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[Eratosthenes]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=37</guid>
		<description><![CDATA[Prime Numbers: Positive natural numbers which has exactly two distinct natural number divisors 1 and itself. Sieve Of Eratosthenes is a computer algorithm to find out prime numbers upto a specified integer starting from 2. The time complexity of a unfaithful sieve is Θ(n2/(log n)2) ( regardless of what wikipedia might say ) I tried [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Prime Numbers</strong>: Positive natural numbers which has exactly two <strong>distinct</strong> natural number divisors 1 and itself.</p>
<p>Sieve Of Eratosthenes is a computer algorithm to find out prime numbers upto a specified integer starting from 2.<br />
The time complexity of a unfaithful sieve is <span style="color: #993300;"><strong>Θ(n2/(log n)2)</strong></span> ( regardless of what wikipedia might say <img src='http://www.think-lamp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  )</p>
<p><span id="more-37"></span></p>
<p>I tried the program in PhP ( for all the php enthusiast <img src='http://www.think-lamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). There is a cool animation ( I found ) for proper understanding:</p>
<div class="wp-caption aligncenter" style="width: 455px"><img title="Sieve of Eratosthenes" src="http://upload.wikimedia.org/wikipedia/commons/c/c8/Animation_Sieve_of_Eratosth-2.gif" alt="Sieve of Eratosthenes in PHP" width="445" height="369" /><p class="wp-caption-text">Sieve of Eratosthenes in PHP</p></div>
<pre class="brush: php;">
/**
* Nishchay Shah                    August 10 2008
*
* Program: To find prime numbers
* Algorithm: Sieve of Eratosthenes
*
* Memory And Time Cost:
*        09552  bytes for 20 numbers        ( 250 to 380 usec )
*        49920 bytes for 100 numbers        ( 1600 to 2500 usec )
*        114.1 K bytes for 500 numbers    ( 230 to 350 msec )
*
*
*/
echo&quot;
&lt;pre&gt;;&quot;; // for browser output
$max = 10;   // find prime numbers till this value. [ Change it for the higher limit. Please dont go crazy.]

/// Populate the scan array
for($i=2;$i&amp;lt;$max;$i++){
$scan[]= $i;
}
/// Call the function
primeNumber($scan);

/// Function to find prime numbers
function primeNumber($scan){
$tempFound = array(); // declare array,save memory
global $primeNumbers;
$number = current($scan); // current data pointer

foreach($scan as $remainingNumber) {
if(!fmod($remainingNumber,$number)){
$tempFound[] = $remainingNumber; //make list of multiples
} // end of if mod = 0
} // end foreach

$scan = array_diff($scan, $tempFound);     // remove the multiples from the list
$primeNumbers[] =  current($scan);
if(count($scan) !=1){
primeNumber($scan);
} // end if count is not 1
else{
return;
}
} // end of function primeNumber

/// Add 2 in the beginning ..
$primeNumbers = array_pad($primeNumbers, -(count($primeNumbers)+2), 0);
$primeNumbers= array(2) + $primeNumbers;
/// Output
print_r($primeNumbers);&lt;/pre&gt;
</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F08%2Fsieve-of-eratosthenes-in-php%2F&amp;linkname=Sieve%20of%20Eratosthenes%20in%20PhP"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Basic dead lock example</title>
		<link>http://www.think-lamp.com/2008/08/basic-dead-lock-example/</link>
		<comments>http://www.think-lamp.com/2008/08/basic-dead-lock-example/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 14:18:46 +0000</pubDate>
		<dc:creator>sshukla</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dead lock]]></category>
		<category><![CDATA[deadlock]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=15</guid>
		<description><![CDATA[A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. It is often seen in a paradox like &#8216;the chicken or the egg&#8216;. WikiPage : http://en.wikipedia.org/wiki/Deadlock deadlock_test1.php &#38;lt;?php $fp1 = fopen&#40;&#34;foo1.txt&#34;, &#34;w&#34;&#41;; if &#40;flock&#40;$fp1, LOCK_EX&#41;&#41; &#123; print &#34;Got lock for foo1.txt!n&#34;; sleep&#40;10&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>A <strong>deadlock</strong> is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. It is often seen in a <a title="Paradox" href="http://en.wikipedia.org/wiki/Paradox">paradox</a> like &#8216;<a class="mw-redirect" title="The chicken or the egg" href="http://en.wikipedia.org/wiki/The_chicken_or_the_egg">the chicken or the egg</a>&#8216;.</p>
<p><span id="more-15"></span></p>
<p><strong>WikiPage : </strong>http://en.wikipedia.org/wiki/Deadlock</p>
<p><strong>deadlock_test1.php<br />
</strong><code><br />
</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000088;">$fp1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo1.txt&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp1</span><span style="color: #339933;">,</span> LOCK_EX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Got lock for foo1.txt!n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$fp2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo2.txt&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #339933;">,</span> LOCK_EX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Got lock foo2.txt!n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #339933;">,</span> LOCK_UN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp1</span><span style="color: #339933;">,</span> LOCK_UN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>deadlock_test2.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000088;">$fp1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo2.txt&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp1</span><span style="color: #339933;">,</span> LOCK_EX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Got lock foo2.txt!n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$fp2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo1.txt&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #339933;">,</span> LOCK_EX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Got lock foo1.txt!n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #339933;">,</span> LOCK_UN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">flock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp1</span><span style="color: #339933;">,</span> LOCK_UN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>Run deadlock_test1.php and deadlock_test2.php in 2 different shell at a same time to get dead lock. <img src='http://www.think-lamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F08%2Fbasic-dead-lock-example%2F&amp;linkname=Basic%20dead%20lock%20example"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2008/08/basic-dead-lock-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hello Lamp-World !</title>
		<link>http://www.think-lamp.com/2008/08/hello-world/</link>
		<comments>http://www.think-lamp.com/2008/08/hello-world/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 04:16:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[what is lamp]]></category>

		<guid isPermaLink="false">http://nishchayshah.com/think-lamp/?p=1</guid>
		<description><![CDATA[Welcome to the world of LAMP. For all you disgraceful people who don&#8217;t know what it is, the definition: L = &#62; Linux ( Its an operating system ) A =&#62; Apache ( Its a web server ) M =&#62; MySQL ( Its a database system ) P =&#62; PhP {&#38;perl } ( These are [...]]]></description>
			<content:encoded><![CDATA[<h4><span style="color: #993300;">Welcome to the world of LAMP.</span></h4>
<h4><span style="color: #993300;">For all you disgraceful people who don&#8217;t know what it is, the definition:</span></h4>
<h4><span style="color: #993300;"><strong>L</strong> = &gt; <strong>Linux </strong>( Its an operating system )<br />
<strong>A</strong> =&gt; <strong>Apache </strong>( Its a web server )<br />
<strong>M</strong> =&gt; <strong>MySQL </strong>( Its a database system )<br />
<strong>P</strong> =&gt; <strong>PhP</strong> {&amp;<strong>perl</strong> } ( These are programming languages )</span></h4>
<h4><span style="color: #993300;"><strong>Wiki page:</strong> http://en.wikipedia.org/wiki/LAMP_(software_bundle)</span></h4>
<h4><span style="color: #993300;">We, here, at Lamp-World are group of people who live eat and think lamp.  This site is aimed to have a collection of amazing &#8216;scripts&#8217; , &#8216;tweaks&#8217; and &#8216;solutions&#8217; which you may not find anywhere else.</span></h4>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F08%2Fhello-world%2F&amp;linkname=Hello%20Lamp-World%20%21"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2008/08/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
