title: How to write to file from command line PHP?
body: <p>I'm trying to write some command line PHP - is there a trick to writing to a file from the command line using PHP?  The file is called testcl.php and I execute it with:</p>
  
  <pre><code>/usr/bin/php -f /var/www/html/media/testcli.php
  
  $myFile = "test.txt";
  $fh = fopen($myFile, 'a');
  fwrite($fh, "batman2");
  fclose($fh);
  echo "batman";
  </code></pre>
  
  <p>The batman echo statement works, so I know the file is running - but it's not writing to test.txt for some reason.  If I access testcli.php it writes text.txt successfully - so I think I'm missing some trick.</p>