<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
	<title>Compiled Weekly &#187; command</title>
	<atom:link href="http://www.compiledweekly.com/tag/command/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.compiledweekly.com</link>
	<description>Compiled weekly is a weekly podcast for open source developers. Topics include PHP, MySQL, wxWidgets, NSIS and more.</description>
	<lastBuildDate>Thu, 24 Jun 2010 16:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<!-- podcast_generator="Blubrry PowerPress/1.0.8" mode="advanced" entry="normal" -->
	<itunes:summary>Compiled weekly is a weekly podcast for open source developers. Topics include PHP, MySQL, wxWidgets, NSIS and more.

Compiled weekly will soon be covering Android SDK. Stay tuned!</itunes:summary>
	<itunes:author>Angelo Mandato</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.compiledweekly.com/wp-content/themes/angelo2/images/itunes_cw.png" />
	<itunes:owner>
		<itunes:name>Angelo Mandato</itunes:name>
		<itunes:email>compiledweekly@gmail.com</itunes:email>
	</itunes:owner>
	<managingEditor>compiledweekly@gmail.com (Angelo Mandato)</managingEditor>
	<copyright>&#xA9; 2006-2008 Compiled Weekly</copyright>
	<itunes:subtitle>Compiled weekly is a weekly podcast for open source developers. Topics include PHP, MySQL, wxWidgets, NSIS and more.</itunes:subtitle>
	<itunes:keywords>programming, php, mysql, wxwidgets, apache, lighttpd, nsis, web design</itunes:keywords>
	<image>
		<title>Compiled Weekly &#187; command</title>
		<url>http://www.compiledweekly.com/wp-content/themes/angelo2/images/rss_cw.png</url>
		<link>http://www.compiledweekly.com</link>
	</image>
	<itunes:category text="Education">
		<itunes:category text="Education Technology" />
	</itunes:category>
	<itunes:category text="Technology">
		<itunes:category text="Podcasting" />
		<itunes:category text="Software How-To" />
	</itunes:category>
		<item>
		<title>Integrating PHP Command Line Scripts with Existing Web Projects</title>
		<link>http://www.compiledweekly.com/2009/01/06/integrating-php-command-line-scripts-with-existing-web-projects/</link>
		<comments>http://www.compiledweekly.com/2009/01/06/integrating-php-command-line-scripts-with-existing-web-projects/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 15:17:14 +0000</pubDate>
		<dc:creator>angelo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[php-cli]]></category>
		<category><![CDATA[verbose]]></category>

		<guid isPermaLink="false">http://www.compiledweekly.com/?p=116</guid>
		<description><![CDATA[After reading the post on Johan Mares site about the PHP command line interface, I thought I would indulge in the details how I&#8217;ve been using the PHP cli for some of my web based applications. First, some of my web apps have multiple configuration files which are determined by the $_SERVER['HTTP_HOST'] value. If (stricmp( [...]]]></description>
			<content:encoded><![CDATA[<p>After reading the post on <a title="Johan Mares" href="http://blog.johan-mares.be/ict/php/running-php-shell-scripts/" target="_blank">Johan Mares</a> site about the PHP command line interface, I thought I would indulge in the details how I&#8217;ve been using the PHP cli for some of my web based applications.</p>
<p>First, some of my web apps have multiple configuration files which are determined by the $_SERVER['HTTP_HOST'] value. If (stricmp( $_SERVER['HTTP_HOST'],&#8217;compiledweekly&#8217;) ) { // then I load compiledweekly config file }. So with that in mind, I had to add to the top of my cli scripts the following line:</p>
<p style="padding-left: 30px;">$_SERVER['HTTP_HOST'] = &#8216;compiledweekly.com&#8217;;</p>
<p>This required me to have to edit the command line script every time i used it with another site. Here&#8217;s the trick: pass arguments to your command line so your script can parse them. Here&#8217;s how I did it to also include a verbose mode.</p>
<pre>	if( count($argv) > 1 )
	{
		for( $x = 1; $x < count($argv); $x++ )
		{
			switch($argv[$x])
			{
				case '--verbose': { // Print results to std out
					$Verbose = true;
				}; break;
				case '--host': { // Print results to std out
					$_SERVER['HTTP_HOST'] = trim($argv[$x+1]);
				}; break;
			}
		}
	}

	if( $Verbose ) echo "Starting script...\n\n";
	// Continue with your script below</pre>
<p>So with the following example I can run my script for my compiledweekly.com site with verbose information. Example:</p>
<p style="padding-left: 30px;">/path/to/script.php --verbose --host compiledweekly.com</p>
<p>Now if you use your php script in a cron task, don't include the --verbose and make sure you check the $Verbose flag before printing any results. Don't forget to add to the end of the command line " &gt; /dev/null 2&gt;&amp;1" minus the quotes, this sends any std out and std error messages to a <a title="What does &gt; /dev/null 2&gt;&amp;1 mean" href="http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/" target="_blank">black hole</a>.<em><br />
</em></p>
<p>If your command line script is saved in a web accessible folder, here's a line you should add to the top so no web browser can execute your script:</p>
<p style="padding-left: 30px;">if( php_sapi_name() != 'cli' ) die('Access denied.');</p>
<p>This will take your command line apps to a new level while giving you the ability to use existing web code.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.compiledweekly.com/2009/01/06/integrating-php-command-line-scripts-with-existing-web-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
