Stopping Parallel Execution of PHP Script
<p>I am trying to stop my cron script from allowing it to run in parallel. I need it so that if there is no current execution of it, the script will be allowed to run until it is complete, the script timesout or an exception occurs.</p>

<p>I have been trying to use the PHP flock function to engage a file lock, run the script and then release the lock. However, it still looks like I am able to run the script multiple times in parallel. Am I missing something?</p>

<p>Btw, I am developing on Mac OS X with the Mac filesystem, maybe this is the reason the file locks are being ignored? Though the PHP documentation only looks about NTFS filesystems?</p>

<pre><code>        // Construct cron lock file path
    $cronLockFilePath = realpath(APPLICATION_PATH . '/locks/cron');

    // Get cron lock file
    $cronLockFile = fopen($cronLockFilePath, 'r');

    // Lock cron lock file
    if (flock($cronLockFile, LOCK_EX)) {

echo 'lock';
sleep(10);

    } else {

echo 'no lock';
    }
</code></pre>
