<?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; pear</title>
	<atom:link href="http://blog.rajatpandit.com/tag/pear/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>Writing a php command line based app using Console_CommandLine</title>
		<link>http://blog.rajatpandit.com/2009/10/17/writing-a-php-command-line-based-app-using-console_commandline/</link>
		<comments>http://blog.rajatpandit.com/2009/10/17/writing-a-php-command-line-based-app-using-console_commandline/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 12:40:05 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Console_CommandLine]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=358</guid>
		<description><![CDATA[I am currently writing a PHP app which had to have a command line interface. I came across this excellent library in PEAR Console_CommandLine. Its core functionality is very useful...]]></description>
			<content:encoded><![CDATA[<p>I am currently writing a <a href="http://php.net">PHP</a> app which had to have a command line interface. I came across this excellent library in <a href="http://pear.php.net">PEAR</a> <a href="http://pear.php.net/manual/en/package.console.console-commandline.php">Console_CommandLine</a>. Its core functionality is very useful out of the box and in case you need to do something really fancy, there is nothing stopping you from extending it further. </p>
<p>Here is a quick example for anyone interested in getting up and running with it.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once 'Console/CommandLine.php';

$parser = new Console_CommandLine();
$parser-&gt;description = 'A fantastic command line program that does nothing.';
$parser-&gt;version = '1.5.0';
$parser-&gt;addOption('filename', array(
    'short_name'  =&gt; '-f',
    'long_name'   =&gt; '--file',
    'description' =&gt; 'write report to FILE',
    'help_name'   =&gt; 'FILE',
    'action'      =&gt; 'StoreString'
));
$parser-&gt;addOption('quiet', array(
    'short_name'  =&gt; '-q',
    'long_name'   =&gt; '--quiet',
    'description' =&gt; &quot;don't print status messages to stdout&quot;,
    'action'      =&gt; 'StoreTrue'
));
try {
    $result = $parser-&gt;parse();
    // do something with the result object
    print_r($result-&gt;options);
    print_r($result-&gt;args);
} catch (Exception $exc) {
    $parser-&gt;displayError($exc-&gt;getMessage());
}
</pre>
<p>gives the output for <code>yourscript -help</code></p>
<pre class="brush: bash; title: ; notranslate">
A fantastic command line program that does nothing.

Usage:
  tmp.php [options]

Options:
  -f FILE, --file=FILE  write report to FILE
  -q, --quiet           don't print status messages to stdout
  -h, --help            show this help message and exit
  --version             show the program version and exit
</pre>
<p>Details for options/configuration:<a href="http://pear.php.net/manual/en/package.console.console-commandline.options.php"> http://pear.php.net/manual/en/package.console.console-commandline.options.php</a></p>
<p>Details for command line arguments: <a href="http://pear.php.net/manual/en/package.console.console-commandline.arguments.php">http://pear.php.net/manual/en/package.console.console-commandline.arguments.php</a></p>
<p>Details for extending lib: <a href="http://pear.php.net/manual/en/package.console.console-commandline.extending.php">http://pear.php.net/manual/en/package.console.console-commandline.extending.php</a></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/10/17/writing-a-php-command-line-based-app-using-console_commandline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP CodeSniffer and common errors</title>
		<link>http://blog.rajatpandit.com/2009/10/01/php-code-sniffer-and-common-errors/</link>
		<comments>http://blog.rajatpandit.com/2009/10/01/php-code-sniffer-and-common-errors/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:06:29 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[code sniffer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[phpcs]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=382</guid>
		<description><![CDATA[I am currently writing a wrapper for PHPUnit for my employer which makes writing Selenium test cases for developers far easier. It would abstract them from the details of knowing...]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-384" title="sniffer11a" src="http://blog.rajatpandit.com/wp-content/uploads/2009/10/sniffer11a.jpg" alt="sniffer11a" width="322" height="193" />I am currently writing a wrapper for <a href="http://phpunit.de">PHPUnit</a> for my <a href="http://ipcmedia.com">employer</a> which makes writing <a href="http://seleniumhq.org/">Selenium</a> test cases for developers far easier. It would abstract them from the details of knowing server, urls, browser versions, reporting etc. All they now need to do is just write a basic test case for the functionality they added in the sprint and then potentially this can be added into hudson for continuous  integration. This was interesting and requires a blog post to document the classes I extended. However this post is more about the next steps. This also would be a great help for the testing team to amass regression suite written by the developer itself, which if done properly would be of the highest quality.</p>
<p>So the next step was to make a pear package out of it so that other projects could extend out of it and also to free the developer of the include path hell that php offers and as part of the exercise, I ran my code past php code sniffer. However good the tool is, its lacking on part of documentation (or atleast i couldn&#8217;t find much) and its obscure error messages only meant that I would have to dig into the code to find out what exactly it was looking for. So here are some of them of the obscure ones:</p>
<pre class="brush: bash; title: ; notranslate">
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 2 | ERROR | Missing file doc comment
 2 | ERROR | Missing class doc comment
--------------------------------------------------------------------------------
</pre>
<p>There isn&#8217;t any documentation that points out what it actually means with file document and class document. It turns out that it needs documentation about the class as well as the class, usually the same if there is only one level. Here is what I put in my class file to satisfy that.</p>
<pre class="brush: php; title: ; notranslate">
/**
* IPC_Test_Config
*
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@lalaland.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
/**
* IPC_Test_Config
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@lalaland.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
</pre>
<p>Here&#8217;s the next one:</p>
<pre class="brush: bash; title: ; notranslate">
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 10 | WARNING | PHP version not specified
--------------------------------------------------------------------------------
</pre>
<p>Now typically you would expect another @tag but its just <code>* PHP version 5</code> that you need to add. This is what the final version looks like:</p>
<pre class="brush: php; title: ; notranslate">
/**
* IPC_Test_Config
*
* PHP version 5
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@ipcmedia.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
/**
* IPC_Test_Config
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@ipcmedia.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
class IPC_Test_Config
</pre>
<p>I hope this post if useful for anyone who wants to use a code sniffer to ensure that the quality of code is kept to its highest.</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/10/01/php-code-sniffer-and-common-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

