I recently had to use semaphores to avoid running an update of a database concurrently.
For testing it I used two browser windows (chrome) on the same Desktop.
In this case semaphores did not work as expected.
Also flock on a file did not work as expected.
Running the script from command line did work as expected.
As soon as I used two different browsers, one on my desktop another within a virutal machine, it works like expected.
Hope that helps anybody avoiding strange debugging sessions on this topic...