<?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>Bohack &#187; php</title>
	<atom:link href="http://www.bohack.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bohack.com</link>
	<description>Check In and Tune Out!</description>
	<lastBuildDate>Sun, 08 Jan 2012 20:59:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>A Simple PHP mail() Function For Testing SMTP Delivery</title>
		<link>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/</link>
		<comments>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:05:00 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=385</guid>
		<description><![CDATA[Making sure mail is sent properly from a PHP website is a bit difficult when it’s not your server, like shared hosting. So I created a simple php script called testmail.php that sends mail via the mail() function.<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/' addthis:title='A Simple PHP mail() Function For Testing SMTP Delivery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Making sure mail is sent properly from a PHP website is a bit difficult when it’s not your server, like shared hosting. You never have access to the mail logs, so you can’t see mail moving. I host several websites on shared hosting and recently found my CMS was not sending emails to me. So I opened a ticket and I concluded it to be a SNAFU.</p>
<p><span id="more-385"></span>I’m never satisfied when I conclude something doesn’t work because it’s complex. The best thing to do is to snap into diagnostic mode. The first rule of diagnosis of the problem is start simple and work from there. The saying of getting to the root of the problem is accurate.</p>
<p>I looked at the CMS code and concluded that the function being called to send mail is the PHP function of mail(). So I needed to check the PHP mail function by itself, without the complexity of the CMS. If the mail() function sends mail, then the problem is the CMS or my email. If the mail() function does not send mail, then my provider has something that they can work with and I can present the problem to them. Simple I created a simple PHP script called testmail.php with this short little string of code:</p>
<pre>&lt;?php
$to = 'youraccount@youremail.com';
$subject = 'Sent on '.date("F j, Y, g:i a");
$message = 'Test message';

mail($to, $subject, $message);
?&gt;
</pre>
<p>This routine will send mail to the $to variable and also tag the date in the subject. This is all done via the sendmail variable in php, you can do a phpinfo() to find which program sends mail. This can be handy if you need to see when it left the other system and came into yours. Just look the original header and you will be able to see all details.</p>
<p>In the end my problem resulted in my SPAM filter catching the email thus never showing up in the Inbox. Stupid problem, but until you verify the flow of mail with your hosting provider and scale your complexity back… You won’t solve the problem.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/' addthis:title='A Simple PHP mail() Function For Testing SMTP Delivery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Page Stop Watch</title>
		<link>http://www.bohack.com/2009/01/php-page-stop-watch/</link>
		<comments>http://www.bohack.com/2009/01/php-page-stop-watch/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 01:20:50 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=261</guid>
		<description><![CDATA[Lots of time I have web pages performing complex functions and want to make sure that they execute without a problem. A problem would be they just take too damn long and time out when put under a load. This is the problem when things don&#8217;t scale properly, they just get really slow. So in [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/01/php-page-stop-watch/' addthis:title='PHP Page Stop Watch ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Lots of time I have web pages performing complex functions and want to make sure that they execute without a problem. A problem would be they just take too damn long and time out when put under a load. This is the problem when things don&#8217;t scale properly, they just get really slow. So in order to gauge how long a page takes to load we really need a stop watch. Luckily we the components of one&#8230;</p>
<p><span id="more-261"></span><br />
The PHP microtime() function returns the UNIX timestamp with micro-seconds.</p>
<pre>&lt;?php echo (microtime()) ?&gt;;   //returns 0.123123 1231231231</pre>
<p>The first number is the microseconds from the change of the second number, which is the time in seconds from the UNIX epoch of 0:00:00 Jan 1st 1970.  So we can explode the line returned into an array using the explode command, then mathematically add them together. i.e. 1231231231.123123. The last line will take the end time and subtract the start time. The result will be displayed in the HTML comments towards the end of the page, where this code is executed.</p>
<pre>Put this at the beginning of your page inside of the php tags.

$start=microtime();
$start=explode(" ",$start);
$start=$start[1]+$start[0];

// do something here

Put this at the end of you page inside of the php tags.

$end=microtime();
$end=explode(" ",$end);
$end=$end[1]+$end[0];

printf("\n&lt;!-- Page was generated by PHP %s in %f seconds --&gt;\n",phpversion(),$end-$start);</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/01/php-page-stop-watch/' addthis:title='PHP Page Stop Watch ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2009/01/php-page-stop-watch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

