protected $longArgSeparator = '=';
protected $timeout = 0;
protected $sudo = false;
+ protected $unique = false;
+ protected $uniqueCommand = null;
function __construct($program, $output = null, $error = true, $outputPrefix = null)
{
}
$endTime = microtime(true);
$this->execTime = $endTime - $startTime;
+ $this->_releaseUniqueLockFile();
+ }
+
+ protected function _releaseUniqueLockFile()
+ {
+ if ($this->isUnique()) {
+ $lock = $this->getUniqueLockFile();
+ if (file_exists($lock)) {
+ unlink($lock);
+ }
+ }
}
public function __set($varname, $value)
public function __destruct()
{
+ $this->_releaseUniqueLockFile();
// if ($this->temp_output && file_exists($this->output)) {
// unlink($this->output);
// }
$this->commande = implode(';', $commandes);
+ if ($this->isUnique()) {
+ $this->uniqueCommand = $this->commande;
+ $lockFile = $this->getUniqueLockFile();
+ while (file_exists($lockFile) && filemtime($lockFile) > time() - 3600) {
+ sleep(3);
+ }
+ touch($lockFile);
+ }
+
if ($output) {
$this->commande .= ' > ' . $output;
}
}
}
+ protected function getUniqueLockFile()
+ {
+ return sys_get_temp_dir() . '/' . hash("sha256", $this->uniqueCommand) . '.lock';
+ }
+
public static function getArgs($argv)
{
array_shift($argv);
$this->sudo = $sudo;
}
+ /**
+ * @return bool
+ */
+ public function isUnique(): bool
+ {
+ return $this->unique;
+ }
+
+ /**
+ * @param bool $unique
+ */
+ public function setUnique(bool $unique): void
+ {
+ $this->unique = $unique;
+ }
+
public function ddCommand()
{
$this->_preExecute();