Exemplo n.º 1
0
 private function loadVars()
 {
     if (!$this->lock->lock()) {
         return;
     }
     if (!shm_has_var($this->memory, self::SID_VARS)) {
         $this->varNames = [];
         shm_put_var($this->memory, self::SID_VARS, $this->varNames);
     } else {
         $this->varNames = shm_get_var($this->memory, self::SID_VARS);
     }
     $this->lock->unlock();
 }
Exemplo n.º 2
0
 public function read()
 {
     $this->_open('r');
     $lock = new Lock($this);
     $lock->sh();
     if ($this->ttl > 0) {
         if (time() - filemtime($this->fileName) >= $this->ttl) {
             $lock->unlock();
             $this->_close();
             unlink($this->fileName);
             return false;
         }
     }
     $content = false;
     while (!feof($this->handle)) {
         $content .= fread($this->handle, 4012);
     }
     $lock->unlock();
     $this->_close();
     return $content;
 }
} else {
    trigger_error("AIESEC-Customer.io-Connector is missing a config file", E_USER_ERROR);
    die;
}
// instantiate KLogger (we don't catch anything here, because we can not do anything about it)
$log = new \Katzgrau\KLogger\Logger(LOG, LOGLEVEL);
$log->log(\Psr\Log\LogLevel::INFO, "AIESEC-Customer.io-Connector is starting.");
// try to get lock
$pid = Lock::lock($log);
// check if we got the lock
if ($pid < 1) {
    // there is a problem or another process running. Shutdown...
    $log->log(\Psr\Log\LogLevel::INFO, "AIESEC-Customer.io-Connector didn't got the lock. This instance is shutting down...");
} else {
    // we got the lock, so check that data directory is writeable
    if (!file_exists('./data') || !is_writeable('./data')) {
        die("data directory must be writeable");
    }
    //try to run the core and sync once
    try {
        $core = new Core($log);
        if ($core) {
            $core->run();
        }
    } catch (Exception $e) {
        // catch all Exception to release the lock before dying.
        $log->log(\Psr\Log\LogLevel::ERROR, "We encountered an unhandled Exception: " . $e->getMessage(), (array) $e->getTrace());
    }
    // unlock the base directory
    Lock::unlock($log);
}
Exemplo n.º 4
0
 /**
  * Tests unlock().
  * 
  * @see Lock::unlock()
  */
 public function testUnlock()
 {
     $name = __FUNCTION__;
     $checkLock = new Lock($name);
     $lock = new Lock($name);
     $lock->lock();
     $lock->unlock();
     $this->assertTrue($checkLock->nonblockingLock());
     $checkLock->unlock();
 }
Exemplo n.º 5
0
<?php

require_once '../shell.php';
if (isset($_POST['ID'])) {
    $id = $_POST['ID'];
    $lock = new Lock($id);
    if ($lock->isLocked()) {
        $lock->unlock();
        $command = escapeshellcmd("python /var/www/python/clear.py");
        echo $command;
        $output = shell_exec($command);
        echo "Output: {$output} <br>";
    } else {
        $lock->lock();
        $command = escapeshellcmd("python /var/www/python/LightsHandler.py allamb on");
        echo $command;
        $output = shell_exec($command);
        echo "Output: {$output} <br>";
    }
}
Exemplo n.º 6
0
 /**
  * @covers Yeriomin\ConsoleApp\Lock::unlock
  */
 public function testUnlockNothing()
 {
     // Nothing happens
     $this->object->unlock();
 }