title: Log Output from php file during cron job
body: <p>I am running a cron job on my local server running Ubuntu 13.10 and want to create a log of the jobs performed.  I can access the main log file, syslog,  that shows if the cron job ran or had errors.</p>
  
  <p>Here is my cronjob (runs every minute while I am testing, script is finished in under a few seconds)</p>
  
  <pre><code>* * * * * /usr/bin/php -f /home/[usr]/web/X/app/application.php &amp;&gt;&gt; /home/[usr]/Maildir/geocode.log 2&gt;&amp;1 # JOB_ID_2
  </code></pre>
  
  <p>Inside my application.php file, I have several echos that output variables and results of queries performed:</p>
  
  <pre><code>echo "STARTING CRON @ ".date("m-d-Y H:i:s")."\r\n";
  echo count($properties) . " properties from query"."\r\n";
  </code></pre>
  
  <p>If I run this file from the command line, the file executes correctly and the output is displayed.  After looking up other questions about cron logs, I thought I needed to output the log file by the second half of the cron job:</p>
  
  <pre><code> &gt;&gt; /home/[usr]/Maildir/geocode.log 2&gt;&amp;1
  </code></pre>
  
  <p>Is this incorrect?  How can I save and log the output from my php file?  My file selects a number of object from a database and performs actions on them.  I want to output the number initially worked on, number successfully completed, and any errors.  Right now nothing is outputted, but I know the cron is running because the database it connects to is being updated correctly.</p>
  
  <p>EDIT:
  I researched some more and thought 2>&amp;1 would pass stderr into stdout because i wanted all of that info, but looks like this was preventing anything from being written.  Using:</p>
  
  <pre><code>/usr/bin/php -f /home/[usr]/web/X/app/application.php &gt;&gt; /home/[usr]/Maildir/geocode.log 
  </code></pre>
  
  <p>Adds all of the output I was expecting into the log file, but I am unsure what will happen with errors because it is running fine now.  I will leave this open in case anyone else wants to add anything about creating a log file and if 2>&amp;1 should ever be used in a situation where we want to keep both stderr and stdout.  </p>