<?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>Techno WeBlog &#187; PHP</title>
	<atom:link href="http://blog.codlib.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codlib.com</link>
	<description>Blogging about tech, the tech, and everything tech, for techno addicts!</description>
	<lastBuildDate>Thu, 04 Nov 2010 04:05:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP: Multiplication without multiplication operator.</title>
		<link>http://blog.codlib.com/2010/02/02/php-multiplication-without-multiplication-operator/</link>
		<comments>http://blog.codlib.com/2010/02/02/php-multiplication-without-multiplication-operator/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 09:32:07 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2010/02/02/php-multiplication-without-multiplication-operator/</guid>
		<description><![CDATA[Recently one of my friend asked me to write a function in PHP for multiplying two numbers without * or / operators. Also we should not use any loops. I got the following solution.
function mul($a,$b)
{
if($b==1){return $a;}
return $a+mul($a,$b-1);
}
echo mul(5,6);
One more solution which i found is as follows. But is is using the division(/) operator.
function mul($a,$b)
{
return $a/(1/$b);
}
echo [...]]]></description>
			<content:encoded><![CDATA[<p>Recently one of my friend asked me to write a function in PHP for multiplying two numbers without * or / operators. Also we should not use any loops. I got the following solution.</p>
<blockquote><p>function mul($a,$b)<br />
{<br />
if($b==1){return $a;}<br />
return $a+mul($a,$b-1);<br />
}</p>
<p>echo mul(5,6);</p></blockquote>
<p>One more solution which i found is as follows. But is is using the division(/) operator.</p>
<blockquote><p>function mul($a,$b)<br />
{<br />
return $a/(1/$b);<br />
}</p>
<p>echo mul(15,3);</p></blockquote>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/09/30/most-wanted-javascript-stringprototype-extensions/" rel="bookmark" class="crp_title">Most Wanted JavaScript String.prototype Extensions</a></li><li><a href="http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/" rel="bookmark" class="crp_title">PHP Header Location &#8211; Page Not found Error.</a></li><li><a href="http://blog.codlib.com/2007/06/22/number-validation-using-javascript/" rel="bookmark" class="crp_title">Number Validation Using JavaScript</a></li><li><a href="http://blog.codlib.com/2008/07/28/passing-multiple-arguments-to-a-javascript-function-at-runtime/" rel="bookmark" class="crp_title">Passing multiple Arguments to a JavaScript Function at Runtime</a></li><li><a href="http://blog.codlib.com/2007/11/26/windowopen-methods-return-value/" rel="bookmark" class="crp_title">window.open() Method&#8217;s Return Value</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2010/02/02/php-multiplication-without-multiplication-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC Song Again &#8211; Video Version</title>
		<link>http://blog.codlib.com/2010/01/07/mvc-song-again-video-version/</link>
		<comments>http://blog.codlib.com/2010/01/07/mvc-song-again-video-version/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 04:26:25 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2010/01/07/mvc-song-again-video-version/</guid>
		<description><![CDATA[Two Years back i have written a post about the MVC(Model-View-Controller) song in this blog. Yesterday while surfing the web I found a video of James singing it live on WWDC 2003 in youtube. Here is the youtube video:

And those who wish to read the lyrics, check it here&#8230; Song about MVC…..Yeah, yeah, yeah
.
Related Posts:How [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://blog.codlib.com/2010/01/07/mvc-song-again-video-version/vidgif/' rel='attachment wp-att-95' title='vid.gif'><img src='http://blog.codlib.com/wp-content/uploads/2010/01/vid.gif' alt='vid.gif' style="float:left; margin:7px;" /></a>Two Years back i have written a <a href="http://blog.codlib.com/2007/11/29/song-about-mvcyeah-yeah-yeah/">post about the MVC(Model-View-Controller) song</a> in this blog. Yesterday while surfing the web I found a video of James singing it live on <a href="http://developer.apple.com/wwdc/">WWDC</a> 2003 in youtube. Here is the youtube video:</p>
<div style="text-align:center;"><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/YYvOGPMLVDo&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YYvOGPMLVDo&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>
<p>And those who wish to read the lyrics, check it here&#8230; <a href="http://blog.codlib.com/2007/11/29/song-about-mvcyeah-yeah-yeah/">Song about MVC…..Yeah, yeah, yeah</a></p>
<p>.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2010/11/03/how-search-works/" rel="bookmark" class="crp_title">How Search Works?</a></li><li><a href="http://blog.codlib.com/2008/05/29/social-media-explained-in-plain-english/" rel="bookmark" class="crp_title">Social Media Explained in Plain English</a></li><li><a href="http://blog.codlib.com/2007/09/18/aol-launches-bluestring/" rel="bookmark" class="crp_title">AOL Launches BlueString</a></li><li><a href="http://blog.codlib.com/2007/11/29/song-about-mvcyeah-yeah-yeah/" rel="bookmark" class="crp_title">Song about MVC&#8230;..Yeah, yeah, yeah</a></li><li><a href="http://blog.codlib.com/2009/06/05/web-30-concepts-explained/" rel="bookmark" class="crp_title">Web 3.0 Concepts explained</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2010/01/07/mvc-song-again-video-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP session is not working in IFrames in IE browsers</title>
		<link>http://blog.codlib.com/2009/06/18/php-session-is-not-working-in-iframes-in-ie-browsers/</link>
		<comments>http://blog.codlib.com/2009/06/18/php-session-is-not-working-in-iframes-in-ie-browsers/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 06:22:05 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2009/06/18/php-session-is-not-working-in-iframes-in-ie-browsers/</guid>
		<description><![CDATA[Recently I have faced an issue with session in IFrames in IE Browsers. The issue is like session is not sharing between pages inside iframe particularly if you are accessing it in a different domain. The script will run smoothly without the iframe, but when i use the iframe in IE and safari it doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have faced an issue with session in IFrames in IE Browsers. The issue is like session is not sharing between pages inside iframe particularly if you are accessing it in a different domain. The script will run smoothly without the iframe, but when i use the iframe in IE and safari it doesn&#8217;t work properly. This is because cross site scripting(XSS) </p>
<p>IE is very particular when it comes to &#8220;cross-site/cross-directory&#8221; linking in iFrames and sessions. If the iFrame contains or calls a script from a different directory then IE does not always pass the session header information. If the contents are called from another domain then absolutely it will not work.</p>
<p>I have eliminated the issue with some workaround. My workaround is as follows. </p>
<ol>
<li> If you notice the iframe SRC in IE browser, you can see that the URL is not modifying when you move to another page. It will   remain as it is and you will not be able to pass any new parameter. I have take this as an advantage and created one token and append it to the initial SRC. It is as follows.
<p>    &lt;iframe src=&#8221;http://www.example.com/?token=&lt;?php echo md5(uniqueid()); ?&gt;&#8221; &gt; &lt;/iframe&gt; </li>
<li>I have created a table for storing session and top of each page i am checking whether the token is exist in database. If it is not exist i am inserting it as a new entry in table. Here token is primary key and session is storing as a serialized object using php serialization function.</li>
<li>In each page i will get the same token from iframe src and i am checking the same exist in db. If exist in db fetch the serialized session, unserialize it and assign back to session.</li>
</ol>
<p>I don&#8217;t know is there any other good solution exists other than this. </p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2009/06/14/html5-new-feature-storage-tables/" rel="bookmark" class="crp_title">HTML5 &#8211; New Feature &#8211; Storage Tables</a></li><li><a href="http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/" rel="bookmark" class="crp_title">PHP Header Location &#8211; Page Not found Error.</a></li><li><a href="http://blog.codlib.com/2007/05/12/web-bugs-hack-or-solution/" rel="bookmark" class="crp_title">Web bugs: hack or solution?</a></li><li><a href="http://blog.codlib.com/2007/11/12/javascript-tips-tricks/" rel="bookmark" class="crp_title">Javascript Tips &#038; Tricks</a></li><li><a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" rel="bookmark" class="crp_title">Need for speed : CSS Compression</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2009/06/18/php-session-is-not-working-in-iframes-in-ie-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Php optimization tips &#8211; Part 1</title>
		<link>http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/</link>
		<comments>http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 12:21:43 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/</guid>
		<description><![CDATA[

 echo is faster than print.
 Wrap your string in single quotes (’) instead of double quotes (”) is faster because PHP searches for variables inside “…”      and not in ‘…’, use this when you’re not using variables you need evaluating in your string.
Use echo’s multiple parameters (or stacked) instead [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://photos.codlib.com/wp-content/uploads/2008/06/php-header-location.jpg" align="right" height="89" width="250" /></p>
<ol>
<li> echo is faster than print.</li>
<li> Wrap your string in single quotes (’) instead of double quotes (”) is faster because PHP searches for variables inside “…”      and not in ‘…’, use this when you’re not using variables you need evaluating in your string.</li>
<li>Use echo’s multiple parameters (or stacked) instead of string concatenation.</li>
<li>Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x &lt; count($array); $x), this calls the count() function each time, use $max=count($array) instead before the for-loop starts.</li>
<li>Use require() instead of require_once() where possible.</li>
<li>Since PHP5, the time of when the script started executing can be found in $_SERVER[’REQUEST_TIME’], use this instead of time() or microtime().</li>
<li>Use &lt;?php … ?&gt; tags when declaring PHP as all other styles are depreciated, including short tags.</li>
<li>Use isset where possible in replace of strlen. (ie: if (strlen($foo) &lt; 5) { echo “Foo is too short”; } vs. if (!isset($foo{5})) { echo “Foo is too short”; } ).</li>
<li>Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x &lt; count($array); $x), this calls the count() function each time, use $max=count($array) instead before the for-loop starts.</li>
<li>Use full paths in includes and requires, less time spent on resolving the OS paths.</li>
</ol>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/12/31/php-string-optimization/" rel="bookmark" class="crp_title">PHP String Optimization</a></li><li><a href="http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/" rel="bookmark" class="crp_title">PHP Header Location &#8211; Page Not found Error.</a></li><li><a href="http://blog.codlib.com/2007/11/12/javascript-tips-tricks/" rel="bookmark" class="crp_title">Javascript Tips &#038; Tricks</a></li><li><a href="http://blog.codlib.com/2008/07/28/passing-multiple-arguments-to-a-javascript-function-at-runtime/" rel="bookmark" class="crp_title">Passing multiple Arguments to a JavaScript Function at Runtime</a></li><li><a href="http://blog.codlib.com/2007/09/30/most-wanted-javascript-stringprototype-extensions/" rel="bookmark" class="crp_title">Most Wanted JavaScript String.prototype Extensions</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Header Location &#8211; Page Not found Error.</title>
		<link>http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/</link>
		<comments>http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 09:22:39 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/</guid>
		<description><![CDATA[
Recently I faced a weird issue with the PHP header location function. I had a line of code in my file like,
Code: header(&#8216;location:mypage.php&#8217;);
In firefox/geeko browsers it is working fine. but in IE when it tries to redirect the page it is showing a &#8220;page not found error&#8221;. I am pretty sure that the page is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://photos.codlib.com/wp-content/uploads/2008/06/php-header-location.jpg" alt="php-header-location" /></p>
<p>Recently I faced a weird issue with the PHP header location function. I had a line of code in my file like,</p>
<blockquote><p>Code: header(&#8216;location:mypage.php&#8217;);</p></blockquote>
<p>In firefox/geeko browsers it is working fine. but in IE when it tries to redirect the page it is showing a &#8220;page not found error&#8221;. I am pretty sure that the page is exist in my server and I checked the spelling and case also. everything is fine. following is the header call i am using. I searched in google and asked few of my friends. Also I<br />
found lots of post related to this in forums and all. But didn&#8217;t see a good solution anywhere. Finally, from the Php header manual page itself, I got the solution.</p>
<p>The reason behind this mysterious behaviour is, HTTP/1.1 requires an absolute URI as argument to Location:  including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF']  and dirname() to make an absolute URI from a relative one yourself:</p>
<blockquote><p>&lt;?php<br />
$host  = $_SERVER['HTTP_HOST'];<br />
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), &#8216;/\\&#8217;);<br />
$extra = &#8216;mypage.php&#8217;;<br />
header(&#8220;Location: http://$host$uri/$extra&#8221;);<br />
exit;<br />
?&gt;</p></blockquote>
<p>Also, It would be good if you use a capital L and put a space before the url like</p>
<blockquote><p>header(&#8220;Location: http://$host$uri/$extra&#8221;);</p></blockquote>
<p>This solves my issue. I never used absolute path with header location in any of my projects. This is the first time I am getting this error. But, going forward, i am thinking that it would be good if i use absolute paths in my location urls. I don&#8217;t know any other impact for this or not.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/" rel="bookmark" class="crp_title">Php optimization tips &#8211; Part 1</a></li><li><a href="http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/" rel="bookmark" class="crp_title">Need for speed : JavaScript Compression</a></li><li><a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" rel="bookmark" class="crp_title">Need for speed : CSS Compression</a></li><li><a href="http://blog.codlib.com/2007/11/26/windowopen-methods-return-value/" rel="bookmark" class="crp_title">window.open() Method&#8217;s Return Value</a></li><li><a href="http://blog.codlib.com/2009/06/18/php-session-is-not-working-in-iframes-in-ie-browsers/" rel="bookmark" class="crp_title">PHP session is not working in IFrames in IE browsers</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable mod_rewrite module in apache</title>
		<link>http://blog.codlib.com/2008/05/06/how-to-enable-mod_rewrite-module-in-apache/</link>
		<comments>http://blog.codlib.com/2008/05/06/how-to-enable-mod_rewrite-module-in-apache/#comments</comments>
		<pubDate>Tue, 06 May 2008 08:18:37 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search Engine]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2008/05/06/how-to-enable-mod_rewrite-module-in-apache/</guid>
		<description><![CDATA[How to check weather mod_rewrite module is enabled or not?
The very simple technique to check weather mod_rewrite module is enabled or not in you web server.
1) Type  in a php file and save it and run that file in the server.
2) And now you can the list of information, just search the word “mod_rewrite” [...]]]></description>
			<content:encoded><![CDATA[<p><b>How to check weather mod_rewrite module is enabled or not?</b></p>
<p>The very simple technique to check weather mod_rewrite module is enabled or not in you web server.</p>
<p>1) Type <?php phpinfo(); ?> in a php file and save it and run that file in the server.<br />
2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu.<br />
3) If it is found under the “Loaded Modules” section then this module is already loaded. Otherwise you need to enable mod_rewrite module.</p>
<p><b>To enable mod_rewrite module in apache installed under windows environment.</b></p>
<p>1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.<br />
2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.<br />
3) Remove the “#” at the starting of the line, “#” represents that line is commented.<br />
4) Now restart the apache server.<br />
5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/07/05/100-windows-keyboard-shortcuts/" rel="bookmark" class="crp_title">100 Windows keyboard shortcuts</a></li><li><a href="http://blog.codlib.com/2007/06/03/how-do-i-include-another-file-inside-a-html-file/" rel="bookmark" class="crp_title">How do I include another file inside a HTML file?</a></li><li><a href="http://blog.codlib.com/2007/05/12/web-bugs-hack-or-solution/" rel="bookmark" class="crp_title">Web bugs: hack or solution?</a></li><li><a href="http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/" rel="bookmark" class="crp_title">How to Display Server Load in PHP</a></li><li><a href="http://blog.codlib.com/2008/05/11/what-is-web20/" rel="bookmark" class="crp_title">What is web2.0 ?</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2008/05/06/how-to-enable-mod_rewrite-module-in-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP String Optimization</title>
		<link>http://blog.codlib.com/2007/12/31/php-string-optimization/</link>
		<comments>http://blog.codlib.com/2007/12/31/php-string-optimization/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 09:29:52 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2007/12/31/php-string-optimization/</guid>
		<description><![CDATA[You can seek a bit more speed out of your code, especially if you have LOTS of strings, by using single quotes and concanetating variables.
$string = &#8216;this is a string with &#8216;.$foo.&#8217; in it&#8217;;
// is marginally faster than
$string = &#8220;this is a string with $foo in it&#8221;;
The reason is php has to search through the [...]]]></description>
			<content:encoded><![CDATA[<p>You can seek a bit more speed out of your code, especially if you have LOTS of strings, by using single quotes and concanetating variables.</p>
<blockquote><p>$string = &#8216;this is a string with &#8216;.$foo.&#8217; in it&#8217;;</p></blockquote>
<p>// is marginally faster than</p>
<blockquote><p>$string = &#8220;this is a string with $foo in it&#8221;;</p></blockquote>
<p>The reason is php has to search through the string to find the variable.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2008/08/12/php-optimization-tips-part-1/" rel="bookmark" class="crp_title">Php optimization tips &#8211; Part 1</a></li><li><a href="http://blog.codlib.com/2007/09/30/most-wanted-javascript-stringprototype-extensions/" rel="bookmark" class="crp_title">Most Wanted JavaScript String.prototype Extensions</a></li><li><a href="http://blog.codlib.com/2007/11/12/javascript-tips-tricks/" rel="bookmark" class="crp_title">Javascript Tips &#038; Tricks</a></li><li><a href="http://blog.codlib.com/2007/06/22/number-validation-using-javascript/" rel="bookmark" class="crp_title">Number Validation Using JavaScript</a></li><li><a href="http://blog.codlib.com/2007/07/09/javascript-equivalent-of-php-function-preg_replace/" rel="bookmark" class="crp_title">JavaScript equivalent of php function preg_replace</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2007/12/31/php-string-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Display Server Load in PHP</title>
		<link>http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/</link>
		<comments>http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 05:20:45 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/</guid>
		<description><![CDATA[When developing a PHP application or monitoring a web server, it’s important to know what your server load is to properly identify that there is a problem.
For those interested, there is a very easy way to output your load in PHP using the exec function.
See the code below.
$load = exec(”uptime”);
$load = split(”load average:”, $load);
$load = [...]]]></description>
			<content:encoded><![CDATA[<p>When developing a PHP application or monitoring a web server, it’s important to know what your server load is to properly identify that there is a problem.</p>
<p>For those interested, there is a very easy way to output your load in PHP using the exec function.<br />
See the code below.</p>
<blockquote><p>$load = exec(”uptime”);<br />
$load = split(”load average:”, $load);<br />
$load = split(”, “, $load[1]);<br />
$load = $load[0];<br />
echo “Current Load: $load”;</p></blockquote>
<p>Place that snippet wherever you want in your PHP application to output the current server load.</p>
<p>Of course, since “uptime” is a Unix command this won’t work on Windows servers, and from what I understand, there’s no easy solution for those users.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/06/03/how-do-i-include-another-file-inside-a-html-file/" rel="bookmark" class="crp_title">How do I include another file inside a HTML file?</a></li><li><a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" rel="bookmark" class="crp_title">Need for speed : CSS Compression</a></li><li><a href="http://blog.codlib.com/2010/01/06/what-is-cdn/" rel="bookmark" class="crp_title">What is CDN?</a></li><li><a href="http://blog.codlib.com/2009/06/14/html5-new-feature-storage-tables/" rel="bookmark" class="crp_title">HTML5 &#8211; New Feature &#8211; Storage Tables</a></li><li><a href="http://blog.codlib.com/2007/07/05/100-windows-keyboard-shortcuts/" rel="bookmark" class="crp_title">100 Windows keyboard shortcuts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Need for speed : JavaScript Compression</title>
		<link>http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/</link>
		<comments>http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 04:55:20 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/</guid>
		<description><![CDATA[This is a continuation to my previous post Need for speed : CSS. I have used PHP to compress my JavaScript files.
Why compression and How?
Javascript files for larger sites can become pretty large themselves. Gzipping or compressing these files has shown to provide a reduction in the neighborhood of 70-80% of the original file size, [...]]]></description>
			<content:encoded><![CDATA[<p>This is a continuation to my previous post <a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" title="Need for Speed : CSS" target="_blank">Need for speed : CSS</a>. I have used PHP to compress my JavaScript files.</p>
<p><strong>Why compression and How?</strong><br />
Javascript files for larger sites can become pretty large themselves. Gzipping or compressing these files has shown to provide a reduction in the neighborhood of 70-80% of the original file size, a fairly significant &#8216;weight loss&#8217;.</p>
<p>With that in mind have made a very quick test for compressing Javascript with GZIP via PHP. I am using the same method mentioned in <a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" title="Need for Speed : CSS" target="_blank">Need for speed : CSS</a> Post. In fact, I am using the same script, but changing the header type to text/javascript vice text/css.</p>
<p>For the code I followed the first method and inserted this into my Javascript files:</p>
<blockquote><p>&lt;?php<br />
ob_start (&#8220;ob_gzhandler&#8221;);<br />
header(&#8220;Content-type: text/javascript; charset: UTF-8&#8243;);<br />
header(&#8220;Cache-Control: must-revalidate&#8221;);<br />
$offset = 60 * 60 ;<br />
$ExpStr = &#8220;Expires: &#8221; .<br />
gmdate(&#8220;D, d M Y H:i:s&#8221;,<br />
time() + $offset) . &#8221; GMT&#8221;;<br />
header($ExpStr);<br />
?&gt;</p></blockquote>
<p>heyyy&#8230;. dont forgot to rename your javascript file with PHP extension. In your HTML you just need to call your Javascript in a different manner:</p>
<blockquote><p> &lt;script type=&#8221;text/javascript&#8221; src=&#8221;path/to/javascript.php&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>vice the normal:</p>
<blockquote><p> &lt;script type=&#8221;text/javascript&#8221; src=&#8221;path/to/javascript.js&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>The second method will also work as well. In your .htaccess though you will want to change the extension name:</p>
<blockquote><p>AddHandler application/x-httpd-php .js<br />
php_value auto_prepend_file gzip-js.php<br />
php_flag zlib.output_compression On</p></blockquote>
<p>Thus you will also want to create gzip-js.php with the changes mentioned above.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/11/13/need-for-speed-css/" rel="bookmark" class="crp_title">Need for speed : CSS Compression</a></li><li><a href="http://blog.codlib.com/2007/06/03/how-do-i-include-another-file-inside-a-html-file/" rel="bookmark" class="crp_title">How do I include another file inside a HTML file?</a></li><li><a href="http://blog.codlib.com/2008/06/16/top-5-html-accessibility-practises/" rel="bookmark" class="crp_title">Top 5 HTML Accessibility Practises.</a></li><li><a href="http://blog.codlib.com/2007/06/22/number-validation-using-javascript/" rel="bookmark" class="crp_title">Number Validation Using JavaScript</a></li><li><a href="http://blog.codlib.com/2007/11/22/reveal-the-contents-of-password-fields/" rel="bookmark" class="crp_title">Reveal The Contents of Password Fields</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Need for speed : CSS Compression</title>
		<link>http://blog.codlib.com/2007/11/13/need-for-speed-css/</link>
		<comments>http://blog.codlib.com/2007/11/13/need-for-speed-css/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 05:16:09 +0000</pubDate>
		<dc:creator>Jans</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://blog.codlib.com/2007/11/13/need-for-speed-css/</guid>
		<description><![CDATA[A powerful advantage of using PHP is that you can compress your files so that they take up less room on your server. There are multiple ways of achieving this, one method is as follows:
&#60;?php
ob_start(&#8220;ob_gzhandler&#8221;);
?&#62;
Just add that to the very beginning of main.php or global.php or whatever. Right now the file may be very small [...]]]></description>
			<content:encoded><![CDATA[<p>A powerful advantage of using PHP is that you can compress your files so that they take up less room on your server. There are multiple ways of achieving this, one method is as follows:</p>
<blockquote><p>&lt;?php<br />
ob_start(&#8220;ob_gzhandler&#8221;);<br />
?&gt;</p></blockquote>
<p>Just add that to the very beginning of main.php or global.php or whatever. Right now the file may be very small anyway, but in a real-world situation it would contain much more code. You’ll soon see the speed benefits of this simple file compression method.</p>
<p>You can import your CSS as a PHP file. This offers you a range of options for creating CSS on the fly using arrays and variables and means you can compress your style rules too. Just add this PHP header to the beginning of your CSS:</p>
<blockquote><p>&lt;?php<br />
ob_start (&#8220;ob_gzhandler&#8221;);<br />
header(&#8220;Content-type: text/css&#8221;);<br />
header(&#8220;Cache-Control: must-revalidate&#8221;);<br />
$offset = 60 * 60 ;<br />
$ExpStr = &#8220;Expires: &#8221; .<br />
gmdate(&#8220;D, d M Y H:i:s&#8221;,<br />
time() + $offset) . &#8221; GMT&#8221;;<br />
header($ExpStr);<br />
?&gt;</p></blockquote>
<p>Remember to save your CSS file with the PHP extension and import it properly.You can do this as follows&#8230;&#8230;..</p>
<blockquote><p> @import url(mycss.php);</p></blockquote>
<p>The above method, though not as clean, it is just as effective. All you need to do is place the PHP snippet from above into the top of your CSS document. Then, rename your CSS file with a &#8216;php&#8217; extension, and then refer to that file when linking your css file. Thats all&#8230;.</p>
<p><strong> Alternative Method</strong><br />
=================<br />
The following method is cleaner and more elegant, as it does not require the addition of any extra code to your CSS file, nor do you have to change the extension of the file. Clean and simple.</p>
<p>Two steps are necessary to implement this method.</p>
<p>Step one:<br />
First, you want to save the snippet provided above in a file called &#8216;gzip-css.php&#8217; to the directory that contains your CSS files.</p>
<p>Step two:<br />
Here, simply add the following to an .htaccess file and save the file to the same directory as your CSS files:</p>
<blockquote><p>AddHandler application/x-httpd-php .css<br />
php_value auto_prepend_file gzip-css.php<br />
php_flag zlib.output_compression On</p></blockquote>
<p>This code does 3 things:</p>
<p>1. The first line tells Apache to send all .css files to the PHP script handler.<br />
2. The second line prepends the code snippet to your CSS file.<br />
3. The third line tells PHP to use its built-in negotiated output compression automatically for every page it parses. This is optional. If you use this method for compression, there is no need for having ob_start (&#8220;ob_gzhandler&#8221;); in the code snippet.</p>
<p>So in this way you can keep your CSS file as it is without any name change.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.codlib.com/2007/11/14/need-for-speed-javascript-compression/" rel="bookmark" class="crp_title">Need for speed : JavaScript Compression</a></li><li><a href="http://blog.codlib.com/2007/11/26/windowopen-methods-return-value/" rel="bookmark" class="crp_title">window.open() Method&#8217;s Return Value</a></li><li><a href="http://blog.codlib.com/2007/06/03/how-do-i-include-another-file-inside-a-html-file/" rel="bookmark" class="crp_title">How do I include another file inside a HTML file?</a></li><li><a href="http://blog.codlib.com/2008/06/25/php-header-location-page-not-found-error/" rel="bookmark" class="crp_title">PHP Header Location &#8211; Page Not found Error.</a></li><li><a href="http://blog.codlib.com/2007/11/15/how-to-display-server-load-in-php/" rel="bookmark" class="crp_title">How to Display Server Load in PHP</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.codlib.com/2007/11/13/need-for-speed-css/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

