<?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"
	>

<channel>
	<title>Philhosting.Net &#124; Internet Articles &#124; Updates &#124; Tips &#38; Tricks &#187; PHP</title>
	<atom:link href="http://philhosting.net/articles/cat/programming/php/feed" rel="self" type="application/rss+xml" />
	<link>http://philhosting.net/articles</link>
	<description>Philhosting.Net &#124; Internet Articles &#124; Updates &#124; Tips &#38; Tricks</description>
	<pubDate>Fri, 05 Dec 2008 11:54:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>PHP : Optimizing</title>
		<link>http://philhosting.net/articles/php-optimizing.html</link>
		<comments>http://philhosting.net/articles/php-optimizing.html#comments</comments>
		<pubDate>Thu, 25 Sep 2008 07:52:40 +0000</pubDate>
		<dc:creator>Root</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Optimizing]]></category>

		<guid isPermaLink="false">http://philhosting.net/articles/?p=47</guid>
		<description><![CDATA[So you have a huge site with multiple PHP Scripts and you get a load of traffic all of a sudden, when you built the site you didn&#8217;t figured 0.01 second load time was fine right? Well, say you get 5,000 visitors daily; that 0.01 can turn into 50 seconds!!!
Don&#8217;t know how to benchmark your [...]]]></description>
			<content:encoded><![CDATA[<p>So you have a huge site with multiple PHP Scripts and you get a load of traffic all of a sudden, when you built the site you didn&#8217;t figured 0.01 second load time was fine right? Well, say you get 5,000 visitors daily; that 0.01 can turn into 50 seconds!!!</p>
<p>Don&#8217;t know how to benchmark your script? It&#8217;s easy:</p>
<div class="code">$start = microtime();<br />
 //your script here<br />
 $end = microtime();<br />
 $time = $start - $end;<br />
 echo(round($time, 3));<br />
 //your script here<br />
 $end = microtime();<br />
 $time = $start - $end;<br />
 echo(round($time, 3));</div>
<p><strong>Now, lets turn that frown of yours upside-down.</strong></p>
<p>Echo is faster than Print (marginally, but it all adds up)</p>
<div class="code">Benchmark:<br />
 Print:<br />
 0.000314<br />
 0.00031<br />
 0.000387</p>
<p>Echo:<br />
 0.000177<br />
 0.000168<br />
 0.000235</p>
</div>
<p>Unset variables and arrays (especially); this will only help load speeds if your servers ram is full and strangling it, though it is still a good practice to unset variables and arrays when you no longer need them.</p>
<p>Use full paths in Include and Requires, this allows the server to be a zombie; and not have to resolve the filepath constantly.</p>
<div class="code">Benchmark<br />
 include(&#8221;file&#8221;)<br />
 0.014752 (omit)<br />
 0.000335<br />
 0.000331<br />
 0.000327</p>
<p>include(&#8221;./file&#8221;)<br />
 0.000179<br />
 &lt; 0.000001 (omit)<br />
 0.000117<br />
 0.000111</p>
</div>
<p>Don&#8217;t limit yourself to just Logic statements, use select() for statements that would better suit it, don&#8217;t just assume that if/then/else will cover it all, because it might; but it can become slow if you have a huge list of redundancies.</p>
<p>Suppressing errors with the @ sign can be extremely slow. Instead use error_reporting(0)</p>
<div class="code">Benchmark:<br />
 @include(&#8221;file-does-not-exist.php&#8221;)<br />
 0.000241<br />
 0.000243<br />
 0.000238<br />
 0.000251</p>
<p>error_reporting(0);<br />
 include(&#8221;file-does-not-exist.php&#8221;)<br />
 &lt; 0.000001<br />
 &lt; 0.000001<br />
 0.000122<br />
 0.00012</p>
</div>
<p>Close DB connections when you no-longer need them, this is along the same lines as unsetting variables; but will give your database some breathing room.</p>
<p>Calling arrays with single quotes is much faster than no quotes ($array['1'] is faster than $array[1])</p>
<div class="code">Benchmark:<br />
 No Quotes<br />
 0.000128<br />
 0.000136<br />
 0.000137<br />
 0.000133</p>
<p>Single Quotes<br />
 &lt; 0.000001<br />
 &lt; 0.000001<br />
 &lt; 0.000001<br />
 &lt; 0.000001</p>
</div>
<p>Globals are marginally slower than variables (only noticeable in duplicate applications).</p>
<div class="code">Benchmark:<br />
 echo($_SERVER['REMOTE_PORT']); (x5)<br />
 0.000173<br />
 0.000785<br />
 0.00017<br />
 0.000169</p>
<p>$var = $_SERVER['REMOTE_PORT'];<br />
 echo($var); (x5)<br />
 &lt; 0.000001<br />
 0.000157<br />
 &lt; 0.000001<br />
 &lt; 0.000001</p>
</div>
<p>Use single quotes for strings instead of double quotes (if you use double quotes, PHP searches for strings inside the string)</p>
<div class="code">Benchmark:<br />
 Double:<br />
 0.000146<br />
 0.000149<br />
 0.000155<br />
 0.00015</p>
<p>Single:<br />
 &lt; 0.000001<br />
 &lt; 0.000001<br />
 &lt; 0.000001<br />
 &lt; 0.000001</p>
</div>
<p>Use static HTML where possible, PHP can be up to <em>TWENTY</em> times slower than HTML. This is due to the fact that PHP compiles the script every time you call it, go learn how to cache the files. If you run a dedicated or VPS server, you will want to ask your host about ZendOptimizer for your PHP Installation. You can check to see if you already have it: php_info your server and CTRL+F for &#8220;Zend&#8221; and it should bring up it&#8217;s own block of info. If it&#8217;s installed, you should have at least basic caching setup.</p>
<p>$add++ is slower than ++$add</p>
<div class="code">Benchmark:</p>
<p>$var++<br />
 0.00032<br />
 0.000314<br />
 0.000319<br />
 0.000273</p>
<p>++$var<br />
 0.000161<br />
 0.000173<br />
 0.00018<br />
 0.00012</p>
</div>
<p>Don&#8217;t make everything in OOP, as this will end up just adding overhead, use OOP for things that should be in OOP, and nothing more.</p>
<p>Use the default PHP functions where possible, no sense in making your own function that does the same thing as a pre-defined default function.</p>
<p>For those of you that have servers buckling under the stress of traffic, you may consider taking all PHP out of your site&#8217;s pages and making different scripts that are run once nightly by a cronjob that will then build the HTML files for your site. This keeps the site dynamic, but also keeps the server from dropping to it&#8217;s knees every time a page is loaded by a visitor.</p>
<p>Also: If you believe my benchmark&#8217;s are skewed because I ran them at the same time, you will be happy to know that I ran the slower methods before running the faster methods. I&#8217;ve also put (omit) next to each of the results that seem to have hit extreme peaks or dips in performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://philhosting.net/articles/php-optimizing.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Sending Email through PHP scripts</title>
		<link>http://philhosting.net/articles/sending-email-through-php-scripts.html</link>
		<comments>http://philhosting.net/articles/sending-email-through-php-scripts.html#comments</comments>
		<pubDate>Wed, 09 Jul 2008 01:18:20 +0000</pubDate>
		<dc:creator>Root</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[mail()]]></category>

		<category><![CDATA[php mail]]></category>

		<category><![CDATA[phpmailer]]></category>

		<guid isPermaLink="false">http://philhosting.net/articles/?p=37</guid>
		<description><![CDATA[
Most Linux hosting doesn&#8217;t allow direct mail sending through PHP mail() function due to spam security issue. In order to send email through PHP mail() function, you need to be authenticate first by the SMTP server. Simplest way to do is to use the PHPMailer. Below is the sample  php code using PHPMailer.
&#60;?php
 include(&#8221;class.phpmailer.php&#8221;);
 $mail [...]]]></description>
			<content:encoded><![CDATA[<div id="article_content">
<p>Most Linux hosting doesn&#8217;t allow direct mail sending through PHP mail() function due to spam security issue. In order to send email through PHP mail() function, you need to be authenticate first by the SMTP server. Simplest way to do is to use the <a href="http://sourceforge.net/project/showfiles.php?group_id=26031" target="_blank">PHPMailer</a>. Below is the sample  php code using PHPMailer.</p>
<p class="p1"><span style="color: #0000ff; font-size: x-small;"><strong>&lt;?php</strong></span></p>
<p class="p1"><span style="color: #0000ff; font-size: x-small;"><strong> include(&#8221;class.phpmailer.php&#8221;);<br />
 $mail = new PHPMailer();<br />
 $mail-&gt; IsSMTP();<br />
 $mail-&gt;Host = &#8220;mail.yourdomain.com&#8221;;<br />
 $mail-&gt;SMTPAuth = true;<br />
 $mail-&gt;Username = &#8220;youruseremail@yourdomain.com&#8221;;<br />
 $mail-&gt;Password = &#8220;yourpassword&#8221;;<br />
 $mail-&gt;From = &#8220;youremail@yourdomain.com&#8221;;<br />
 $mail-&gt;FromName = &#8220;YourName&#8221;;<br />
 $mail-&gt;AddAddress($To-EmailAddress);<br />
 $mail-&gt;AddReplyTo(&#8221;youremail@yourdomain.com&#8221;, &#8220;YourName&#8221;);<br />
 $mail-&gt;IsHTML(true);<br />
 $mail-&gt;Subject = &#8220;subject is here&#8221;;<br />
 $mail-&gt;Body = &#8220;full body message here&#8221;;<br />
 $mail-&gt;AltBody = &#8220;full body message same here&#8221;;</strong></span></p>
<p class="p1"><span style="color: #0000ff; font-size: x-small;"><strong> if(!$mail-&gt;Send())<br />
 <span class="Apple-converted-space"> </span>{<br />
 $Confirm = &#8220;Error in sending!<span class="Apple-converted-space"> </span>Message hasn&#8217;t been sent&#8221;;<br />
 }<br />
 else<br />
 {<br />
 <span class="Apple-converted-space"> </span>$Confirm = &#8220;Message has been sent&#8221;;<br />
 }<br />
 ?&gt;</strong></span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://philhosting.net/articles/sending-email-through-php-scripts.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
