Skip to content

Instantly share code, notes, and snippets.

@juliensnz
Last active December 7, 2015 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliensnz/7143aaee3dc2d4dfa194 to your computer and use it in GitHub Desktop.
Save juliensnz/7143aaee3dc2d4dfa194 to your computer and use it in GitHub Desktop.
Simple php code to only run if no file are locked
<?php
/**
* Utility class to test if you can take a control over a locked file
*/
class Despot {
/**
* Try to take the control of a file
*/
public static function putsch($key)
{
$f = fopen(sys_get_temp_dir() . '/' . $key, 'w');
return $f && flock($f, LOCK_EX | LOCK_NB);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment