<?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>Roshan Bhattarai's Blog -  A blog about PHP, Ajax, JavaScript, CSS and Web 2.0 &#187; coding technique</title>
	<atom:link href="http://roshanbh.com.np/category/coding-technique/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Thu, 10 Jun 2010 11:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CodeIgniter : A recommendation for PHP Programmer</title>
		<link>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html</link>
		<comments>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html#comments</comments>
		<pubDate>Thu, 11 Dec 2008 19:12:25 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=324</guid>
		<description><![CDATA[I was thinking to publish this post way before but between my irregularity and busy schedule I couldn&#8217;t do that. Today, I would like to tell you that Why I choose CodeIgniter for my current project and recommend it for other programmers? I&#8217;ve used CakePHP for my one previous project in which I&#8217;ve used the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Fcodeigniter-programmer-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Fcodeigniter-programmer-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">I was thinking to publish this post way before but between my irregularity and busy schedule I couldn&#8217;t do that. Today, I would like to tell you that Why I choose CodeIgniter for my current project and recommend it for other programmers? I&#8217;ve used CakePHP for my one previous project in which I&#8217;ve used the version 1.1.7 of Cake. I must admit that CakePHP is a great MVC framework with but there are many performance issues in the related to CakePHP and I decided not to use it until the final version of 1.2.0 of CakePHP which is still in RC phase while writing this post.</p>
<p><span id="more-324"></span></p>
<h4>Why I recommend PHP Programmers to use CodeIgniter?</h4>
<p style="text-align: justify;">Yes I&#8217;ve decided to use it along with this I&#8217;ve asked my programmer friends out there in office to use it. You&#8217;re wondering why I choose CodeIgniter rather than using Zend Framework, which  add more values in PHP programmer&#8217;s career.Let&#8217; me answer them all in the reasons below.</p>
<ol>
<li>The main issue which I got attracted with CodeIgniter is its performance. CodeIgniter is faster than other popular PHP MVC frameworks. Take a look at these Benchmark test done by <a href="http://en.wikipedia.org/wiki/Rasmus_Lerdorf" target="_blank">Rasmus Lerdorf</a>(creator of PHP programming), <a href="http://talks.php.net/show/froscon08/25">here</a> , <a href="http://talks.php.net/show/froscon08/29">here</a> in <a href="http://talks.php.net/show/froscon08/25">here</a>. And also take a look at <a href="http://www.avnetlabs.com/php/php-framework-comparison-benchmarks">another benchmark test</a> . So it&#8217;s clear that CI is faster than other Framework. Rasmus also told that he liked <a href="http://codeigniter.com/">CodeIgniter</a> because it is faster, lighter and the least like a framework.</li>
<li>Another main reason behind recommendation, it has very low learning curve. CodeIgniter Downloads come with a tremendous user guide which is  a great documentation like PHP Manual to begin with. And from my personal experience, CodeIgniter has very low learning curve compared to CakePHP and Zend Framework. If you&#8217;re a beginner for PHP frameworks then I recommend to go with CodeIgniter at begining.</li>
<li>The coding conventions are flexible and simple. Ironically, CakePHP has very strict coding conventions so you must be very careful about cases of characters while coding.</li>
<li>Why not Zend Framework and why CodeIgniter? Ok, one question goes here what is so good about Zend Framwork ? Eventual answer is ZF contain huge set of libraries and classes compared to any other framework. OK I agree, but another great news is that You can use <a href="http://www.4webby.com/freakauth/tutorials/using-zend-framework-components-in-code-igniter" target="_blank">Zend Framework&#8217;s classes in the CodeIgniter </a>using hooks in CI. So you can use huge amount of Zend&#8217;s libraried in CI as well.</li>
</ol>
<p style="text-align: justify;">These are the main reason why I recommend for using CodeIgniter for PHP programmers.But I still believe that I&#8217;ll be using CakePHP for once I get final version of 1.2.0 because I still believe that it is robust,  has a  great design patters and great tool for group development .</p>
<p>If you recommend any other PHP framework, please let us know why you recomment that framework.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=324&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html</link>
		<comments>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:58:22 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=320</guid>
		<description><![CDATA[From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.<br />
<span id="more-320"></span></p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p style="text-align: justify;">We&#8217;re working on a website which was similar to <a rel="nofollow" href="http://www.swoopo.co.uk/" target="_blank">http://www.swoopo.co.uk/</a> and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.</p>
<p>First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using <a href="http://httpd.apache.org/docs/2.0/programs/ab.html" target="_blank">Apache benchmark tool</a>(ab) 50 request with concurrency of 50 with the following command.</p>
<blockquote><p><span style="color: #993300;">ab -n 50 -c 50 http://xyz.com/ajax_page.php</span></p></blockquote>
<p>And then in another SSH shell prompt, I run the <a href="http://linux.about.com/od/commands/l/blcmdl1_top.htm">top</a> command to view the CPU usages parallelly.</p>
<p>I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.</p>
<h4>How did I reduced the CPU overload drastically caused by MySql?</h4>
<p>Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.</p>
<ol>
<li>I created another PHP file in which I&#8217;ve transferred the mysql query causing CPU overhead and called it from Cronjob.</li>
<li>Created a temporary table for storing the output given by  PHP page called from CronJob.</li>
<li>Then, I scheduled the CronJob in every second, don&#8217;t tell me that CronJob can&#8217;t be run less than a minute, <a href="http://www.macosxhints.com/article.php?story=20070516060214429" target="_blank">take a look at this post before saying this</a>.And from each call, the output data was stored in the temporary table.</li>
<li>And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.</li>
</ol>
<p>I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.</p>
<p>I know I can further reduce the CPU overhead by storing the temporary data in a text file. You guyz know that I&#8217;m lazy so that part is left for another day.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=320&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>PHP Framworks !! Why , when and which ?</title>
		<link>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html</link>
		<comments>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html#comments</comments>
		<pubDate>Mon, 17 Nov 2008 10:57:51 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php framework]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=311</guid>
		<description><![CDATA[Well!! I know it&#8217;s been a long time, but what to do so many things to do and I&#8217;m having hard time to maintain this blog these days.Hope I will be regular like I was before. Today, I&#8217;m going to talk about some of the popular MVC PHP frameworks. A few people has asked me [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F11%2Fphp-framworks-why-when-and-which.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F11%2Fphp-framworks-why-when-and-which.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Well!! I know it&#8217;s been a long time, but what to do so many things to do and I&#8217;m having hard time to maintain this blog these days.Hope I will be regular like I was before. Today, I&#8217;m going to talk about some of the popular MVC PHP frameworks. A few people has asked me what is CakePHP, or What is CodeIgniter? How to to use them ? When to use them ? Today, I&#8217;m going to talk about PHP frameworks which I&#8217;ve used. Please note that the choice of choosing a framework is personal preference and the statement and this post is not going to say that this framework is better than this framework.<br />
<span id="more-311"></span></p>
<h4>What are the benefits of using MVC PHP frameworks ?</h4>
<p>Well there are many benefits of using PHP frameworks, let&#8217;s see some of the main benefits of using them.</p>
<ol>
<li>They PHP frameworks follows some <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" target="_blank">design pattern</a>, so when you use these framework you&#8217;ve to follow their coding convention which makes your code clean and extensible for future purpose.</li>
<li>The Popular PHP frameworks like <a href="http://www.cakephp.org" target="_blank">CakePHP</a>, <a href="http://www.codeigniter.com">CodeIgniter</a>, <a href="http://framework.zend.com" target="_blank">Zend Framework</a> , <a href="www.symfony-project.org" target="_blank">Symfony</a> follows <a href="http://en.wikipedia.org/wiki/Model-view-controller">Model View Controller(MVC) design pattern</a> which separates business logic from user interface making the code cleaner and extensible.</li>
<li>As everybody can guess, these frameworks contains   a lot of libraries to make your job easier. For example, to validate a from you don&#8217;t have write much code as you&#8217;ve to in normal coding scenario, just few lines of code calling the library might be enough for it.</li>
<li>While working on a large project in a team, these MVC PHP framework will be a great tool for development as you can assign a developer to develop MVC part of a module for a developer and integration will be quite easy of these developed module at final level.</li>
<li>These MVC framework will really helps you to develop the project rapidly, if you know one framework well then you&#8217;ll never worry about the project deadline.</li>
<li>Most of these MVC frameworks uses clear url approach making your web project SEO friendly.</li>
</ol>
<p>Furthermore, if you want charge money to visitors who download or access  content of your website then this software is highly useful.</p>
<h4>What are disadvantage of using MVC PHP frameworks?</h4>
<p>A coin has two parts similarly a bright stuff always have dark part as well .</p>
<ol>
<li>Different framework have different coding convention, Depending upon the the framework, you&#8217;ll have to learn coding convention for the framework you want to follow. So depending upon the framework, it might to struggle at the beginning.</li>
<li>While coding  using these framework, sometime you&#8217;ll not find any library or helpers which might be useful for you so you&#8217;ll have to struggle bit at that time.</li>
<li>If you don&#8217;t have OOP experience then PHP MVC framework are not you. First build a solid knowledge of OOP with PHP then only think about choosing any framework.</li>
<li>PHP frameworks are not for the small projects from my point of view, because in a very simple project custom coding will work faster than setting up a framework.</li>
</ol>
<h4>Which framework should I choose?</h4>
<p>This is the one of the most discussed question about the PHP framworks.  So it depends upon particular person and project which framework will best suit for you. But depending upon my experience, I can show you some way to choose the framework.</p>
<ol>
<li>If you&#8217;re just want to use MVC framework for your next project, then I suggest you to go for <a href="http://www.codeigniter.com"><strong>CodeIgniter</strong></a>. It is very easy to learn and well-documented.Furthermore, it&#8217;s very flexible because it is not so strict on naming conventions etc. Furthermore, Model is optional while coding in codeIgniter so it is not necessary to use model for each controllers.</li>
<li>If you&#8217;re coding architecture savvy, then I suggest you to go with <a href="http://www.cakephp.org" target="_blank"><strong>CakePHP</strong></a>, probably the most popular PHP framework but I must admit. This framework&#8217;s coding style is similar to Ruby on Rails and naming conventions are strict in this framework.So if you&#8217;re working on a huge project in a team then this project will be the right choice for you.</li>
<li>If you&#8217;ve to use a lot web services external APIs in your project then<strong> <a href="http://framework.zend.com" target="_blank">Zend Framework</a></strong> will be right choice for you, it contains huge libraries for external APIs compared to any other PHP MVC framework. The main benefits of this framework is that you can use them as components(without using MVC) in your project or you can follow Zend framework&#8217;s MVC architecture to develop your project. The other benefits of this framework is that you can use it inside any of the above two MVC frameworks. And, this framework one of the most favourite of people when I conducted the poll for the <strong><a href="roshanbh.com.np/2008/06/which-is-the-best-php-framework.html">best PHP framework</a></strong> ?</li>
</ol>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=311&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Strucutures of Females in defined by C programmer</title>
		<link>http://roshanbh.com.np/2008/07/strucutures-of-females-in-c-programming.html</link>
		<comments>http://roshanbh.com.np/2008/07/strucutures-of-females-in-c-programming.html#comments</comments>
		<pubDate>Sun, 20 Jul 2008 09:57:41 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[humor]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=167</guid>
		<description><![CDATA[Today, I&#8217;ve got a interesting email from one of my friend which contains the structure of female defined by a C programmer. This programmer did a research on female and defined their structure in C programming. Checkout these cool structures of females and have fun . &#160; &#160; Struct female_professional s { double styles; short [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fstrucutures-of-females-in-c-programming.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fstrucutures-of-females-in-c-programming.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Today, I&#8217;ve got a interesting email from one of my friend which contains the structure of female defined by a C programmer. This programmer did a research on female and defined their structure in C  programming. Checkout these cool structures of females and have fun <img src='http://roshanbh.com.np/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .</p>
<p><span id="more-167"></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Struct female_professional s<br />
{<br />
double styles;<br />
short skirts;<br />
long time_to_understand_ problems;<br />
float mind;<br />
void knowledge;<br />
char non_co-operative;<br />
}</strong></p>
<p><strong>Struct married_females<br />
{<br />
double weight;<br />
Short tempered;<br />
long gossip;<br />
Float hopes;<br />
void word;<br />
char unstable;<br />
}</strong></p>
<p><strong>Struct engaged_females<br />
{<br />
double time_on_phone;<br />
short attention_on_ work;<br />
long boast;<br />
float on_cloud_nine;<br />
void understanding;<br />
char edgy;<br />
}</strong></p>
<p><strong>Struct newly_married_ females<br />
{<br />
double dinner_invitation;<br />
Short time_at_work;<br />
long lunch_break;<br />
void bank_balance;<br />
char hen_pecked;<br />
}</strong></p>
<p><strong>Struct husband_wife_ professionals<br />
{<br />
double income;<br />
Short tempered;<br />
long time_no_see_ each_other;<br />
void love_life;<br />
char money_making;<br />
}</strong></p>
<p><strong>Struct beautiful_city_ girl<br />
{<br />
double boyfriends;<br />
short affairs;<br />
long stories;<br />
void greymatter;<br />
char flirt;<br />
}</strong></p>
<p><strong>Struct old_lady<br />
{<br />
double chin;<br />
Short memory;<br />
long sighs ;<br />
void attention_from_ men ;<br />
char chatterbox;<br />
} </strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=167&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/strucutures-of-females-in-c-programming.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Which is the best PHP framework ?</title>
		<link>http://roshanbh.com.np/2008/06/which-is-the-best-php-framework.html</link>
		<comments>http://roshanbh.com.np/2008/06/which-is-the-best-php-framework.html#comments</comments>
		<pubDate>Sat, 14 Jun 2008 16:10:10 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[blogs]]></category>
		<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Poll & Competetion]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=127</guid>
		<description><![CDATA[I&#8217;ve been asked a lot of times which is the best PHP framework. Well, it&#8217;s a very difficult question to answer this question and there are some pros and corns in each framework. So, today I would to hear your views via poll. Please let everybody know which is the best PHP framework among CakePHP, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F06%2Fwhich-is-the-best-php-framework.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F06%2Fwhich-is-the-best-php-framework.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">I&#8217;ve been asked a lot of times which is the best PHP framework. Well, it&#8217;s a very difficult question  to  answer this question and there are some pros and corns in each framework. So,  today I would to hear your views via poll.  Please let everybody know which is the <strong>best PHP framework</strong> among <a href="http://www.cakephp.org" target="_blank"> CakePHP</a>, <a href="http://www.symfony-project.org/ " target="_blank">Symfony</a>, <a href="http://framework.zend.com/" target="_blank">Zend Framework</a>, <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> and <a href="http://seagullproject.org/" target="_blank">Seagull</a>. So that, it will be easier for the PHP developer to choose right framework for the next project. And please post the comment, if you&#8217;ve something more to say.</p>
<p><span id="more-127"></span></p>
<p><strong></strong></p>
<div>[poll id="1"]</div>
<p>After looking at the above result is clear that Zend framework is the <strong>best PHP framework</strong>. To learn, Zend Framework you can check the following book from Aspress for learning the best PHP framework as preferred by many PHP developers, Zend Framework.</p>
<pre>
<a rel="nofollow" href="http://affiliate.buy.com/gateway.aspx?adid=17662&amp;aid=10387773&amp;pid=3141609&amp;sURL=http%3A%2F%2Fwww.buy.com%2Fprod%2Fthe-definitive-guide-to-zend-framework%2Fq%2Floc%2F106%2F207891714.html&amp;cjsku=207891714" target="_top"><img src="http://ak.buy.com/db_assets/prod_images/714/207891714.jpg" border="0" alt="The Definitive Guide to Zend Framework" /></a>
<img src="http://www.afcyhf.com/image-3141609-10387773" border="0" alt="" width="1" height="1" />
</pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=127&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/06/which-is-the-best-php-framework.html/feed</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Php function to validate two decimal places of a number</title>
		<link>http://roshanbh.com.np/2008/02/validation-two-decimal-places-php.html</link>
		<comments>http://roshanbh.com.np/2008/02/validation-two-decimal-places-php.html#comments</comments>
		<pubDate>Sun, 10 Feb 2008 10:24:48 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php codes]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/02/validation-two-decimal-places-php.html</guid>
		<description><![CDATA[If you are looking for the validation of a number which contains only two decimal places. Means you want to accept the values like 0.21 or 1.34 or 12.55 or 445.66 as a input and throw an error when somebody enters the number like 0.2 or 4.678 from a text box. Here is a simple [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fvalidation-two-decimal-places-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fvalidation-two-decimal-places-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">If you are looking for the validation of a number which contains only two decimal places. Means you want to accept the values like <font color="#800000">0.21</font> or <font color="#800000">1.34</font> or <font color="#800000">12.55</font> or <font color="#800000">445.66</font> as a input and throw an error when somebody enters the number like <font color="#800000">0.2</font> or <font color="#800000">4.678</font> from a text box. Here is a simple function for you in PHP which validates the number weather it contains exactly two decimal places or not.</p>
<p><span id="more-43"></span></p>
<h4>Function to validate two decimal places of a number in PHP</h4>
<pre style="overflow: auto"><font color="#800000">function validateTwoDecimals($number)
{
   if(ereg('^[0-9]+\.[0-9]{2}$', $number))
	 return true;
   else
	 return false;
}</font></pre>
<p><!--adsense--></p>
<p>Well let me explain the fairly simple regular expression inside the <a href="http://www.php.net/ereg" title="ereg() function of PHP" target="_blank">ereg()</a> function of PHP.</p>
<pre style="overflow: auto"><font color="#800000">^[0-9]+\.[0-9]{2}$</font></pre>
<p align="justify">The hat(<font color="#800000">^</font>) represents the start of the string and the <font color="#800000">[0-9]+</font> tells that there will be one or more digits at the starting of the the string. &#8220;&#8216;<font color="#800000">\.</font>&#8221; represents that there should be a  period(<font color="#800000">.</font>)  after that and <font color="#800000">[0-9]{2}</font> tells that after there should be exactly two digits after period and the dollar sign(<font color="#800000">$</font>) represents the end of the string.</p>
<p><!--adsense--></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=43&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/02/validation-two-decimal-places-php.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Register Globals ( register_globals ) &#8220;on&#8221; security problem in PHP</title>
		<link>http://roshanbh.com.np/2008/02/register_globals-php-security-problem.html</link>
		<comments>http://roshanbh.com.np/2008/02/register_globals-php-security-problem.html#comments</comments>
		<pubDate>Thu, 07 Feb 2008 16:45:21 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/02/register_globals-php-security-problem.html</guid>
		<description><![CDATA[Do you know what happend when register_globals is set to ON in php.ini?? When it is set to ON it registers Environment, GET, POST, COOKIE or Server variables as global variables i.e. you don&#8217;t need to write $_POST['username'] to access the posted &#8216;username&#8217; variable you can simply use &#8216;$username&#8217; to access the $_POST['username']. So you might think that [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fregister_globals-php-security-problem.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fregister_globals-php-security-problem.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Do you know what happend when register_globals is set to ON in php.ini?? When it is set to ON it registers Environment, GET, POST, COOKIE or Server variables as global variables i.e. you don&#8217;t need to write $_POST['username'] to access the posted &#8216;username&#8217; variable you can simply use &#8216;$username&#8217; to access the $_POST['username'].</p>
<p><span id="more-40"></span></p>
<p align="justify">So you might think that making register_globals on is easy for us why not to use?? Yes you are right it will make easy for you but the other thing is that might overlaps the varibles i.e. $username might be $_POST['username'] or $_GET['username'] or $_SESSION['username'] or $_COOKIE['username']. And it creates the conflicts between variables and might also create the security problems.</p>
<p align="justify">Let&#8217;s look at a simple example, Suppose that there is &#8220;<font color="#800000">page1.php</font>&#8221; which assign the values in the session variable,</p>
<pre style="overflow: auto"><font color="#800000"> $_SESSION['user']='roshan';  

</font></pre>
<p><!--adsense--></p>
<p>and in page2.php the following code where somebody relying on the register_globals variable and suppose did like this,</p>
<pre style="overflow: auto"><font color="#800000">if(!empty($user))
{
   //user authenticated process
}
</font></pre>
<p>A malicious user can enter into the authenticated script by adding the user parameter in the get method of <font color="#800000">&#8220;page2.php&#8221; </font>in the following.</p>
<pre style="overflow: auto">    <font color="#800000"> page2.php?user=roshan</font></pre>
<p align="justify">It will take you inside of the user authenticated process. It&#8217;s just a  simple example.Sometime this result might be vulnerable in other cases.</p>
<p>As register_globals issue is quite controversial, PHP community has decided to <a target="_blank" href="http://www.php.net/register_globals" title="php register_globals remove">remove this feature of PHP as part of PHP 6.0.0</a>. So if you&#8217;re relying on the register_globals in your project it&#8217;s time to update your code.</p>
<p>I always recommend PHP using register_globals off in php.ini and in your server.You can check weather it is on or off by using <a target="_blank" href="http://www.php.net/phpinfo" title="phpinfo">phpinfo()</a> function available in PHP.</p>
<p align="justify">Note one thing you can&#8217;t use  <a target="_blank" href="http://www.php.net/ini_set" title="ini_set">ini_set()</a> function to alter the value of register_globals in runtime. You have to use .htaccess file to alter it&#8217;s value.You can write the following line in your .htaccess file to turn the register_globals off.</p>
<p><font color="#800000">php_value register_globals off</font></p>
<p><!--adsense--></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=40&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/02/register_globals-php-security-problem.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to return value from Ajax Function &#8211; Use synchronous request</title>
		<link>http://roshanbh.com.np/2008/01/how-to-return-value-from-ajax-function-use-synchronous-request.html</link>
		<comments>http://roshanbh.com.np/2008/01/how-to-return-value-from-ajax-function-use-synchronous-request.html#comments</comments>
		<pubDate>Tue, 29 Jan 2008 18:42:35 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[coding technique]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[ajax requests]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/01/how-to-return-value-from-ajax-function-use-synchronous-request.html</guid>
		<description><![CDATA[Have you ever tried to return values from the Ajax function ? Well it might be sometime the cases when you might have to return the value got from the server to another function rather than updating the component. Let&#8217;s try to return the values from the traditional Ajax function. &#160; &#160; function getVal(param) { [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fhow-to-return-value-from-ajax-function-use-synchronous-request.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fhow-to-return-value-from-ajax-function-use-synchronous-request.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Have you ever tried to return values from the Ajax function ? Well it might be sometime the cases when you might have to return the value got from the server to another function rather than updating the component.</p>
<p>Let&#8217;s try to return the values from the traditional Ajax function.<br />
<span id="more-37"></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre style="overflow: auto"><font color="#800000">function getVal(param)
{
  var strURL=”findValues.php?val=”+param;
  var req = getXMLHTTP();
  if (req)
  {
    req.onreadystatechange = function()
    {
      if (req.readyState == 4)
      {
        return req.responseText;
      }
    }

    req.open(”GET”, strURL, true);
    req.send(null);
  }
}</font></pre>
<p>And now look at the following statement ,</p>
<p><font color="#800000">alert(getVal(1));</font></p>
<p><!--adsense--></p>
<p align="justify">What does the alert statement displays? Is it the value returned from the server?? Not at all, it alert &#8220;undefined&#8221;. Why so?? What happens here is you are trying to get the synchronous request but the request runs asynchronously.So to return the value, we need to make the request synchronous so that we can return the value from the Ajax function.</p>
<p align="justify">So what is the difference between synchronous request and asynchronous request of Ajax?? In the above example which is asynchronous request, the callback function is called in the background leaving the other activity of your program to flow no matter weather the result is obtained from the server or not. But in the case of synchronous request, JavaScript stop processing your program  until a result has been obtained from the server.</p>
<p>Now let&#8217;s look at the synchronous way of request of the above function</p>
<pre style="overflow: auto"><font color="#800000">
function getVal(param)
{
  var strURL=”findValues.php?val=”+param;
  var req = getXMLHTTP();
  req.open(”GET”, strURL, false); //third parameter is set to false here
  req.send(null);
  return req.responseText;
}</font></pre>
<p>If you look at the open method, the third parameter is false which means the the request should be synchronous, if set to true the request become asynchronous and the callback function and onreadystatechange property must be used.</p>
<p><a href="http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX" title="Ajax Synchronous and asynchronous" target="_blank">Click here to learn more about synchronous request</a>.</p>
<p><!--adsense--></p>
<p align="justify"><strong>Note:You might face the problem of browser stuck, slow website link with the synchronous request of the Ajax so you have keep these things into account before making the synchronous request.</strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=37&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/01/how-to-return-value-from-ajax-function-use-synchronous-request.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Clean and efficient coding technique in PHP</title>
		<link>http://roshanbh.com.np/2007/12/clean-and-efficient-coding-technique-in-php.html</link>
		<comments>http://roshanbh.com.np/2007/12/clean-and-efficient-coding-technique-in-php.html#comments</comments>
		<pubDate>Thu, 13 Dec 2007 07:02:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[clead coding technique]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/clean-and-efficient-coding-technique-in-php/</guid>
		<description><![CDATA[Well there are lots of discussion regarding what the actual &#8220;clean code&#8221; is. At the end of the day you can find there are mainly two criterion for clean code: 1. Efficiency: Does the code run as quickly and efficiently as possible? Does the code make the most of it&#8217;s objects and variables with maximum [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2007%2F12%2Fclean-and-efficient-coding-technique-in-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2007%2F12%2Fclean-and-efficient-coding-technique-in-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify">Well there are lots of discussion regarding what the actual &#8220;clean code&#8221; is. At the end of the day you can find there are <span class="blsp-spelling-error" id="SPELLING_ERROR_0">mainly</span> two criterion for clean code:</p>
<p><span id="more-13"></span><br />
<span style="font-weight: bold">1. Efficiency:</span> Does the code run as quickly and efficiently as possible? Does the code make the most of it&#8217;s objects and variables with maximum reuse and minimal waste?</p>
<p><span style="font-weight: bold">2. Maintainability:</span> Is the code easy to understand for other developers? Is it well planned, logical, well documented, and easy to update?</p>
<p>Let&#8217;s discuss the various elements comprising these two broad points regarding clean code, and example in <span class="blsp-spelling-error" id="SPELLING_ERROR_1">PHP</span>.</p>
<p align="justify">One way or another, all pseudo code is eventually converted to machine code. This code will occupy some finite amount of memory. Some languages, such as Java and the .NET Framework first product IL (Intermediary Language) code before producing machine code. In <span class="blsp-spelling-error" id="SPELLING_ERROR_2">PHP</span>, there are a few key ways to minimize the amount of memory and machine code overhead generated by your application.  The best place to start the discussion is with loops and conditional statements.</p>
<p align="justify"><span style="font-weight: bold">Case Statements</span> &#8211; A case statement produces roughly 1/5<span class="blsp-spelling-error" id="SPELLING_ERROR_3">th</span> the amount of machine code as an if/else structure that completes the same task. Use case statements whenever possible. The difference in memory overhead between these two statements is fairly nominal, but the case statement is more efficient to some small degree.</p>
<p align="justify"><span style="font-weight: bold">Loops </span>- Loops vary more drastically than conditionals due to the nature of the operations they perform. <span class="blsp-spelling-error" id="SPELLING_ERROR_4">PHP</span> offers a number of loops. When deciding what type of loop to use, consider the operations taking place. Let&#8217;s look at the following example, where we have a query that will return around 2000 results.</p>
<p><span style="font-family: trebuchet ms"> $r = <span class="blsp-spelling-error" id="SPELLING_ERROR_5">mysql</span>_query(&#8216;SELECT * FROM <span class="blsp-spelling-error" id="SPELLING_ERROR_6">tablename</span> LIMIT 1500&#8242;);</span><br />
<span style="font-family: trebuchet ms">    //First option</span><br />
<span style="font-family: trebuchet ms">    for ($i = 0; $i &amp;<span class="blsp-spelling-error" id="SPELLING_ERROR_7">lt</span>; <span class="blsp-spelling-error" id="SPELLING_ERROR_8">mysql</span>_<span class="blsp-spelling-error" id="SPELLING_ERROR_9">num</span>_rows($r); $i++) {<br />
<span style="font-family: trebuchet ms">     print <span class="blsp-spelling-error" id="SPELLING_ERROR_10">mysql</span>_result($r, $i, &#8216;<span class="blsp-spelling-error" id="SPELLING_ERROR_11">Col1</span>&#8216;).<span class="blsp-spelling-error" id="SPELLING_ERROR_12">mysql</span>_result($r, $i, &#8216;<span class="blsp-spelling-error" id="SPELLING_ERROR_13">Col2</span>&#8216;);</span><br />
<span style="font-family: trebuchet ms">    }</span></span></p>
<p><span style="font-family: trebuchet ms">    // Second option</span><br />
<span style="font-family: trebuchet ms">    while (($row = <span class="blsp-spelling-error" id="SPELLING_ERROR_14">mysql</span>_fetch_assoc($r)) !== false) {</span><br />
<span style="font-family: trebuchet ms">     print $row['<span class="blsp-spelling-error" id="SPELLING_ERROR_15">Col1</span>'].$row['<span class="blsp-spelling-error" id="SPELLING_ERROR_16">Col2</span>'];</span><br />
<span style="font-family: trebuchet ms">    }</span></p>
<p><!--adsense--></p>
<p align="justify">The first option requires simply one scalar variable used as a counter for iteration, using a lightweight access method to read buffered data from a result handle. The second example uses an array constructor function to build an array and evaluate it&#8217;s contents on each iteration, and then references the array two times per iteration. The <span class="blsp-spelling-error" id="SPELLING_ERROR_17">bottom line</span> is &#8220;SECOND OPTION&#8221; runs significantly faster. It has lower memory and machine code overhead.</p>
<p><span style="font-weight: bold">Best Practices</span></p>
<p align="justify">It is subject to much debate and a variety of standards. Let&#8217;s start the example with single quotes (&#8216;) vs using double quotes (&#8220;). The <span class="blsp-spelling-error" id="SPELLING_ERROR_18">PHP</span> parser treats these two token identifiers very different. <span class="blsp-spelling-error" id="SPELLING_ERROR_19">PHP</span> treats anything inside a matching pair of single quotes as a string literal and does not parse the contents of that string. However, <span class="blsp-spelling-error" id="SPELLING_ERROR_20">PHP</span> treats anything inside a matching pair of double quotes as string data and parse the contents of the string. This can result in major performance disparities in a page with extensive data output. Let&#8217;s test printing 1,000 lines of output in the following two methods:</p>
<p>// First Option<br />
print &#8220;Name  : $name. Address : $add. Email: $email.&#8221;;</p>
<p>// Second Option<br />
print &#8216;Name :&#8217;.$name.&#8217;. Address : &#8216;.$add.&#8217;. Email &#8216;.$email.&#8217;.';</p>
<p align="justify">Can you imagine second option run 30% faster than the first one. The big difference between these two examples is that in first option <span class="blsp-spelling-error" id="SPELLING_ERROR_21">PHP</span> is required to full parse the contents of the string. Second option is the equivalent of concatenating seven string literal values together and printing them out, which requires no actual string parsing.</p>
<p>Other &#8220;best practices&#8221; that are more thoroughly documented include:</p>
<p>* Using a consistent and logical naming convention for objects, functions, classes, etc.<br />
* Commenting code line by line (or as near to line by line as is needed to clearly explain what operations are being performed).<br />
* Indenting code to reflect the beginning and ending of statements (particularly statements enclosed in curly braces).<br />
* Organizing files in a logical directory structure with easy to understand directory and file names.<br />
* Making code as modular and reusable as possible i.e use functions if the same code is going to be used in many places.</p>
<p>These things may seem obvious to seasoned programmers, but for a lot of beginners, these are things that are often overlooked in haste.</p>
<p><!--adsense--></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=13&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2007/12/clean-and-efficient-coding-technique-in-php.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/45 queries in 0.546 seconds using disk: basic
Object Caching 1387/1480 objects using disk: basic

Served from: roshanbh.com.np @ 2012-02-08 21:27:39 -->
