<?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>Connecting the dots... &#187; target</title>
	<atom:link href="http://blog.rajatpandit.com/tag/target/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Infrastructure and Application Scalability</description>
	<lastBuildDate>Thu, 29 Dec 2011 13:21:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PING using php</title>
		<link>http://blog.rajatpandit.com/2009/02/22/ping-using-php/</link>
		<comments>http://blog.rajatpandit.com/2009/02/22/ping-using-php/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 19:09:33 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[awesomeness]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[data structure]]></category>
		<category><![CDATA[exec function]]></category>
		<category><![CDATA[icmp packet]]></category>
		<category><![CDATA[milli seconds]]></category>
		<category><![CDATA[packet loss]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[ping ping]]></category>
		<category><![CDATA[ping statistics]]></category>
		<category><![CDATA[raw data]]></category>
		<category><![CDATA[reply]]></category>
		<category><![CDATA[result object]]></category>
		<category><![CDATA[sequence array]]></category>
		<category><![CDATA[target]]></category>
		<category><![CDATA[trip times]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=227</guid>
		<description><![CDATA[I have been playing around with CURL and its awesomeness for a potential idea and had to use some data retrieved by sending a ICMP packet to the host. This...]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" title="Ping" src="http://leonardoribeiro.info/wp-content/uploads/2008/12/ping.jpg" alt="" width="240" height="240" /></p>
<p>I have been playing around with CURL and its awesomeness for a potential idea and had to use some data retrieved by sending a ICMP packet to the host. This was required to check to check stuff like host availability, packet loss etc. The standard stuff. Doing this would be fairly straightforward if you wanted to use the <code>exec</code> function. However getting the data back as a data structure can be a pain.<br />
Pear has an interesting packge <code>Net/Ping</code> does does all that very neatly for you. Here is the code snippet for that.</p>
<pre class="brush: bash; title: ; notranslate">
&lt;?php
     require_once &quot;Net/Ping.php&quot;;
     $ping = Net_Ping::factory();
     if(PEAR::isError($ping)) {
      echo $ping-&gt;getMessage();
    } else {
      /* Number of packets to send */
      $ping-&gt;setArgs(array('count' =&gt; 4));
      $rawData = $ping-&gt;ping('rajatpandit.com');
      print_r($rawData);
    }

?&gt;
</pre>
<p>and the data that you get back, is a pretty useful <a href="http://www.structuredsettlement-quotes.com">structured</a> array.</p>
<pre class="brush: bash; title: ; notranslate">
Net_Ping_Result Object
(
    [_icmp_sequence] =&gt; Array
        (
            [1] =&gt; 310
            [2] =&gt; 300
            [3] =&gt; 318
            [4] =&gt; 301
        )

    [_target_ip] =&gt; 67.205.0.93
    [_bytes_per_request] =&gt; 32
    [_bytes_total] =&gt; 128
    [_ttl] =&gt; 238
    [_raw_data] =&gt; Array
        (
            [0] =&gt;
            [1] =&gt; Pinging rajatpandit.com [67.205.0.93] with 32 bytes of data:
            [2] =&gt;
            [3] =&gt; Reply from 67.205.0.93: bytes=32 time=310ms TTL=238
            [4] =&gt; Reply from 67.205.0.93: bytes=32 time=300ms TTL=238
            [5] =&gt; Reply from 67.205.0.93: bytes=32 time=318ms TTL=238
            [6] =&gt; Reply from 67.205.0.93: bytes=32 time=301ms TTL=238
            [7] =&gt;
            [8] =&gt; Ping statistics for 67.205.0.93:
            [9] =&gt;     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
            [10] =&gt; Approximate round trip times in milli-seconds:
            [11] =&gt;     Minimum = 300ms, Maximum = 318ms, Average = 307ms
        )

    [_sysname] =&gt; windows
    [_round_trip] =&gt; Array
        (
            [min] =&gt; 300
            [max] =&gt; 318
            [avg] =&gt; 307
        )

    [_transmitted] =&gt; 4
    [_received] =&gt; 4
    [_loss] =&gt; 0
)
</pre>
<p>Sweet!</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/02/22/ping-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

