<?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>code-diesel &#187; php cli</title>
	<atom:link href="http://www.codediesel.com/tag/php-cli/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>7 essential php command-line options</title>
		<link>http://www.codediesel.com/php/7-essential-php-commandline-options/</link>
		<comments>http://www.codediesel.com/php/7-essential-php-commandline-options/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 05:30:24 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[addins]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[php cli]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2163</guid>
		<description><![CDATA[some essential php command-line options for your use]]></description>
			<content:encoded><![CDATA[<p>Most of us use PHP from a IDE or using a simple text editor with a browser, rarely dropping down to the command-line for running php programs. But php provides some interesting and quick options you can use to perform various common tasks or to debug some nasty installation problems. Below is a list of some useful options you should be familiar with.<br />
<span id="more-2163"></span><br />
There are two ways to specify options on the command line &#8211; <em>Short Option</em>, where you specify a option by a single character and a <em>Long Option</em>, where you use a more readable string to specify the option, such as &#8216;&#8211;php-ini&#8217;. In this post we will be using the <em>Short Option</em>.</p>
<h3>PHP Command-line options</h3>
<h4>1 : Using a different php.ini file</h4>
<p>The following option can be useful when you need to test various ini configurations, or you need to check if all the modules in a particular ini are loading correctly.</p>

<div class="wp_codebox"><table><tr id="p21631"><td class="code" id="p2163code1"><pre class="text" style="font-family:monospace;">php –c  PATH/to/PHP.INI example.php</pre></td></tr></table></div>

<h4>2 : Check to see for any syntax errors in a php file.</h4>
<p>Need to quickly check for php syntax errors if you do not have access to an IDE, then this option can be quite helpful. Combine it with some shell code and you can easily check for syntax errors for multiple files in a directory.</p>

<div class="wp_codebox"><table><tr id="p21632"><td class="code" id="p2163code2"><pre class="text" style="font-family:monospace;">php –l example.php</pre></td></tr></table></div>

<p>You can for example use the windows command line script to scan all the php files in the current directory for syntax errors.</p>

<div class="wp_codebox"><table><tr id="p21633"><td class="code" id="p2163code3"><pre class="dos" style="font-family:monospace;">c:\localhost&gt;for <span style="color: #33cc33;">%%</span><span style="color: #448888;">X</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span>*.php<span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> php -l <span style="color: #33cc33;">%%</span><span style="color: #448888;">X</span></pre></td></tr></table></div>

<h4>3 : Display php builtin and loaded modules</h4>

<div class="wp_codebox"><table><tr id="p21634"><td class="code" id="p2163code4"><pre class="text" style="font-family:monospace;">php –m</pre></td></tr></table></div>

<p>Combine it with php –c to debug any module loading errors for different php.ini files</p>

<div class="wp_codebox"><table><tr id="p21635"><td class="code" id="p2163code5"><pre class="text" style="font-family:monospace;">php –c PATH/to/PHP.INI -m</pre></td></tr></table></div>

<p>This came in handy when I was installing php 5.3 and for some reasons the xdebug extension was not loading. With the help of the above command I was able to narrow down the problem to the following reason:</p>

<div class="wp_codebox"><table><tr id="p21636"><td class="code" id="p2163code6"><pre class="text" style="font-family:monospace;">Xdebug requires Zend Engine API version 220090115.
The Zend Engine API version 220090626 which is installed, is newer.
Contact Derick Rethans at http://xdebug.org for a later 
version of Xdebug.</pre></td></tr></table></div>

<h4>4 : Syntax Highlighting</h4>
<p>The following option will display syntax highlighted text using php’s internal mechanism.</p>

<div class="wp_codebox"><table><tr id="p21637"><td class="code" id="p2163code7"><pre class="text" style="font-family:monospace;">php  –s  example.php</pre></td></tr></table></div>

<p>You can then write the output to another file using a redirect.</p>

<div class="wp_codebox"><table><tr id="p21638"><td class="code" id="p2163code8"><pre class="text" style="font-family:monospace;">php  –s  example.php  &gt;  syntax.html</pre></td></tr></table></div>

<h4>5 : Strip the source code of comments and whitespace.</h4>
<p>Can be useful if you need to reduce the file size.</p>

<div class="wp_codebox"><table><tr id="p21639"><td class="code" id="p2163code9"><pre class="text" style="font-family:monospace;">php –w example.php</pre></td></tr></table></div>

<h4>6 : Run php code from the command line</h4>
<p>Directly run php code from the command line without using the php start and end tags.</p>

<div class="wp_codebox"><table><tr id="p216310"><td class="code" id="p2163code10"><pre class="text" style="font-family:monospace;">php -r &quot;$foo = 'hello!'; $foo = strtoupper($foo); echo $foo;&quot;</pre></td></tr></table></div>

<h4>7 : Display information related to a internal function, class or extension</h4>
<p><i>(Available as of PHP 5.1.2)</i><br />
These options can be quite handy when a PHP manual is not within reach.</p>

<div class="wp_codebox"><table><tr id="p216311"><td class="code" id="p2163code11"><pre class="text" style="font-family:monospace;">php --r[fcei]</pre></td></tr></table></div>

<p>Show information about a function:</p>

<div class="wp_codebox"><table><tr id="p216312"><td class="code" id="p2163code12"><pre class="text" style="font-family:monospace;">php --rf usort</pre></td></tr></table></div>

<p>Example output for the above:</p>

<div class="wp_codebox"><table><tr id="p216313"><td class="code" id="p2163code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>standard<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">usort</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #339933;">-</span> Parameters <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    Parameter <span style="color: #009933; font-style: italic;">#0 [ &lt;required&gt; &amp;$arg ]
</span>    Parameter <span style="color: #009933; font-style: italic;">#1 [ &lt;required&gt; $cmp_function ]
</span>  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Show information about a class:</p>

<div class="wp_codebox"><table><tr id="p216314"><td class="code" id="p2163code14"><pre class="text" style="font-family:monospace;">php --rc EmptyIterator</pre></td></tr></table></div>

<p>Example output for the above:</p>

<div class="wp_codebox"><table><tr id="p216315"><td class="code" id="p2163code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>iterateable<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">class</span> EmptyIterator 
          implements Iterator<span style="color: #339933;">,</span> Traversable <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">-</span> Constants <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">-</span> Static properties <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">-</span> Static methods <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">-</span> Properties <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">-</span> Methods <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    Method <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">,</span> prototype Iterator<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method <span style="color: #990000;">rewind</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    Method <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">,</span> prototype Iterator<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method valid <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    Method <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">,</span> prototype Iterator<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method <span style="color: #990000;">key</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    Method <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">,</span> prototype Iterator<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method <span style="color: #990000;">current</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    Method <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SPL<span style="color: #339933;">,</span> prototype Iterator<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method <span style="color: #990000;">next</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Show information about a extension:</p>

<div class="wp_codebox"><table><tr id="p216316"><td class="code" id="p2163code16"><pre class="text" style="font-family:monospace;">php  --re json</pre></td></tr></table></div>

<p>Example output for the above:</p>

<div class="wp_codebox"><table><tr id="p216317"><td class="code" id="p2163code17"><pre class="php" style="font-family:monospace;">xtension <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>persistent<span style="color: #339933;">&gt;</span> extension <span style="color: #009933; font-style: italic;">#10 json version 1.2.1 ] {
</span>
  <span style="color: #339933;">-</span> Functions <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">Function</span> <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>json<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">json_encode</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">Function</span> <span style="color: #009900;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>json<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">json_decode</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Show configuration information for a particular extension:</p>

<div class="wp_codebox"><table><tr id="p216318"><td class="code" id="p2163code18"><pre class="text" style="font-family:monospace;">php  --ri tidy</pre></td></tr></table></div>

<p>Example output for the above:</p>

<div class="wp_codebox"><table><tr id="p216319"><td class="code" id="p2163code19"><pre class="php" style="font-family:monospace;">tidy
&nbsp;
Tidy support <span style="color: #339933;">=&gt;</span> enabled
libTidy Release <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span> August <span style="color: #cc66cc;">2007</span>
Extension Version <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">2.0</span>
<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Id</span><span style="color: #339933;">:</span> tidy<span style="color: #339933;">.</span>c<span style="color: #339933;">,</span>v 1<span style="color: #339933;">.</span>66<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>8<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>24 <span style="color: #cc66cc;">2007</span><span style="color: #339933;">/</span><span style="color:#800080;">09</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">20</span> <span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">:</span><span style="color: #208080;">05</span> nlopess <span style="color: #990000;">Exp</span> $<span style="color: #009900;">&#41;</span>
&nbsp;
Directive <span style="color: #339933;">=&gt;</span> Local Value <span style="color: #339933;">=&gt;</span> Master Value
tidy<span style="color: #339933;">.</span>default_config <span style="color: #339933;">=&gt;</span> no value <span style="color: #339933;">=&gt;</span> no value
tidy<span style="color: #339933;">.</span>clean_output <span style="color: #339933;">=&gt;</span> no value <span style="color: #339933;">=&gt;</span> no value</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/7-essential-php-commandline-options/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

