Issue with flock when running script in cron job
<p>I am using the following code: </p>

<pre><code>$fp = fopen("lock.txt", "w");
if (flock($fp, LOCK_EX|LOCK_NB)) { // do an exclusive lock
    //Do something here.
}else{
   echo "Could not lock file!";
}
</code></pre>

<p>This code runs fine when I run my script from my browser (it locks and I can only run it once) but when running it via cron job, the lock.txt file isn't even created. I am a little stumped as I presume the Cron runs as the same user that runs the browser version so it obviously has permissions.</p>

<p>Anyone else had something like this?</p>

<p>EDIT: Ok the file is created now I have done specific paths to the directory. However, the file is overwritten everytime the cron starts an isn't actually locking the file.</p>
