<?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/category/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>HTTP sessions and background processes on Apache-PHP</title>
		<link>http://www.think-lamp.com/2009/04/http-sessions-and-background-processes-on-apache-php/</link>
		<comments>http://www.think-lamp.com/2009/04/http-sessions-and-background-processes-on-apache-php/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 21:08:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[background process]]></category>
		<category><![CDATA[file descriptor]]></category>
		<category><![CDATA[flock]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[session_start()]]></category>
		<category><![CDATA[session_write_close]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=167</guid>
		<description><![CDATA[OK , so you are all excited about running a 10 minute process and you are happy that you have set the processing as a background process, while the user can surf along your website / CMS. If you are are using sessions, not quite smarty ! Consider this script [parentProcess.php] $backgroundCall = 'php childProcess.php [...]]]></description>
			<content:encoded><![CDATA[<p>OK , so you are all excited about running a 10 minute process and you are happy that<br />
you have set the processing as a background process, while the user can surf along your<br />
website / CMS. If you are are using sessions, not quite smarty !</p>
<p><span id="more-167"></span></p>
<p>Consider this script [parentProcess.php]</p>
<pre class="brush: php;">
$backgroundCall = 'php childProcess.php &amp;gt; /dev/null &amp;amp;';

shell_exec($backgroundCall );

echo &quot;Hello world ! My background job is fired&quot;;

// other code , redirects etc
</pre>
<p>When you call a background file with the &#8216;ampersand&#8217; in the end, it sure becomes a background file.<br />
But it does not mean that the user will get control back of the browser. If you are using sessions,<br />
the webpage will be busy until the background process finishes execution.</p>
<p>Why is that ?</p>
<p><span style="color: #800000;"><em>[There is bug described <a href="http://bugs.php.net/bug.php?id=10675" target="_blank">here</a> and it is still not solved even in the php 5.0+ versions.]</em></span></p>
<p style="text-align: justify;">What happens is that the child process which is called by the <strong>system() ,exec() or shell_exec()</strong> command<br />
holds the file lock on the parent process, thus locking the session file.<br />
Thus, the session file being locked <strong>session_start();</strong> function cannot access the file.<br />
This is due to to open file descriptors locking the session file.Your entire session will be locked, so none of the pages of the website can be opened ( which are under session control )<br />
unless you change the browser or delete cookies.</p>
<h2><span style="color: #ff0000;">Solution:</span></h2>
<p>There are places on the internet which provide C code and perl code to do that. But PHP has its own<br />
function , which sadly is ignored <strong>session_write_close();</strong> This function can be used to trigger the close of session. Thus instructing the session<br />
that there is nothing to write until the next session start. Triggering this before firing background process will not hold locks on<br />
the session file.</p>
<pre class="brush: php;">
$backgroundCall = 'php childProcess.php &amp;gt; /dev/null &amp;amp;';

session_write_close();

shell_exec($backgroundCall );

echo &quot;Hello world ! My background job is fired&quot;;

// other code , redirects etc</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2009%2F04%2Fhttp-sessions-and-background-processes-on-apache-php%2F&amp;linkname=HTTP%20sessions%20and%20background%20processes%20on%20Apache-PHP"><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/04/http-sessions-and-background-processes-on-apache-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Emacs for PHP</title>
		<link>http://www.think-lamp.com/2008/12/emacs-for-php/</link>
		<comments>http://www.think-lamp.com/2008/12/emacs-for-php/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 10:54:35 +0000</pubDate>
		<dc:creator>kinjal.ch</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=127</guid>
		<description><![CDATA[1.download php-mode.el from http://sourceforge.net/projects/php-mode/ 2. copy php-mode.el to emacs/lisp/ 3.byte compile php-mode.el file to get php-mode.elc file command:  M-x byte-compile-file 4.add following lines to you .emacs file (require &#8216;php-mode) (add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.module$&#8221; . php-mode)) (add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.inc$&#8221; . php-mode)) (add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.install$&#8221; . php-mode)) (add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.engine$&#8221; . php-mode)) done! emacs is ready to support php. try C-c C-f [...]]]></description>
			<content:encoded><![CDATA[<p>1.download php-mode.el from <a href="http://sourceforge.net/projects/php-mode/">http://sourceforge.net/projects/php-mode/</a></p>
<p>2. copy php-mode.el to emacs/lisp/</p>
<p>3.byte compile php-mode.el file to get php-mode.elc file</p>
<p>command:  M-x byte-compile-file</p>
<p>4.add following lines to you .emacs file</p>
<p>(require &#8216;php-mode)</p>
<p>(add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.module$&#8221; . php-mode))</p>
<p>(add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.inc$&#8221; . php-mode))</p>
<p>(add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.install$&#8221; . php-mode))</p>
<p>(add-to-list &#8216;auto-mode-alist &#8216;(&#8220;\\.engine$&#8221; . php-mode))</p>
<p>done! emacs is ready to support php.</p>
<p>try C-c C-f on built in php function</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F12%2Femacs-for-php%2F&amp;linkname=Emacs%20for%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/12/emacs-for-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>Fork Bomb</title>
		<link>http://www.think-lamp.com/2008/08/fork-bomb/</link>
		<comments>http://www.think-lamp.com/2008/08/fork-bomb/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 18:38:47 +0000</pubDate>
		<dc:creator>sshukla</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fork bomb]]></category>
		<category><![CDATA[php fork bomb]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=47</guid>
		<description><![CDATA[A fork bomb works by creating a large number of processes very quickly in order to saturate the available space in the list of processes kept by the computer&#8217;s operating system. If the process table becomes saturated, no new programs may be started until another terminates. WikiPage : http://en.wikipedia.org/wiki/Fork_bomb while&#40;1&#41; pcntl_fork&#40;&#41;; Note: Process Control support [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A fork bomb works by creating a large number of processes very quickly in order to saturate the available space in the list of processes kept by the computer&#8217;s <a title="Operating system" href="http://en.wikipedia.org/wiki/Operating_system">operating system</a>. If the process table becomes saturated, no new programs may be started until another terminates. </strong></p>
<p><strong>WikiPage : </strong>http://en.wikipedia.org/wiki/Fork_bomb</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
pcntl_fork<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Note: </strong>Process Control support in PHP is not enabled by default. You have to compile the CGI or CLI version of PHP with &#8211;enable-pcntl configuration option when compiling PHP to enable Process Control support.<br />
Currently, this module will not function on non-Unix platforms (Windows). </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%2Ffork-bomb%2F&amp;linkname=Fork%20Bomb"><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/fork-bomb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
