title: PHP Session Synchronisation
body: <p>I am developing a WebApp in PHP. The user will be able to click a button and the PHP code will end up calling a system exec. Since the WebApp will be using AJAX, there is the possibility that the user could click the button twice, or indeed click another button which would start another exec process.</p>
  
  <p>Now, I know that I could write a little javascript that would disable the buttons until the single event has been completed. However, this is client side enforcement, which can easily been overwritten.</p>
  
  <p>Is there somethig I could do on the PHP side to stop things like this happening? In my head, I have an idea of having a session variable act as a "semaphore" and before every script is executed, this variable would be checked and must return 0 before the script could continue. </p>
  
  <p>Am I going about that the right way? Or does that just open a can of worms for deadlocks/race conditions?</p>
  
  <p>Thanks</p>
  
  <p>Update:
  Just to put it into context, the system I'm developing will be used to start, stop, and reimage Virtual Private Servers. If the reimaging button was pressed, the PHP script will call some bash script to start to re-image the VPSes. However if a user tried to start the VPS while this was being done....</p>