Last active
December 7, 2015 21:33
-
-
Save juliensnz/7143aaee3dc2d4dfa194 to your computer and use it in GitHub Desktop.
Simple php code to only run if no file are locked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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