title: Why Do I Get This Segmentation Fault In This PHP Command Line Script?
body: <p>It's just a quick script to a message to what I call a 'mental log file'. Just to keep track of my thoughts when I drift off and get myself back to work. Anyway, it works alright most of the time, but every so often I get a segmentation fault. Heard of them in C, but never had them before in PHP. Here's the script:</p>
  
  <pre><code>#!/usr/bin/php 
  &lt;?php 
  
      $mental_log_file = "/home/ali/mental-log"; 
      array_shift($argv);      //get rid of the initial arg (name of the command) 
      $log_entry = date('j-n-y H:i') . ' ' . implode(' ', $argv) . "\n";
  
      file_put_contents($mental_log_file, $log_entry, FILE_APPEND);
  </code></pre>
  
  <p>Here's what I get on a few runs:</p>
  
  <pre>
  ali@oem-desktop:~$ mlog blah
  ali@oem-desktop:~$ mlog blah
  Segmentation fault
  ali@oem-desktop:~$ mlog blah
  ali@oem-desktop:~$ mlog blah
  Segmentation fault
  ali@oem-desktop:~$ mlog blah
  ali@oem-desktop:~$ mlog blah
  ali@oem-desktop:~$ mlog blah
  Segmentation fault
  ali@oem-desktop:~$ mlog blah
  ali@oem-desktop:~$ mlog blah
  Segmentation fault
  ali@oem-desktop:~$ mlog blah
  Segmentation fault
  </pre>
  
  <p>Any idea of what I could be doing wrong here? The file seems to be updating correctly as expected even on the runs that produce segmentation faults. I'm running Ubuntu 9.04 Jaunty.</p>
  
  <pre>
  ali@oem-desktop:~$ php --version
  PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 23 2009 14:37:14) 
  Copyright (c) 1997-2008 The PHP Group
  Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
  </pre>
  
  <p>Thanks in advance.</p>