/**
  * Read db data from memory cache daemon
  * @param string $command The command to invoke
  * @param array $args The command arguments
  * @param string &$output The output from the read socket
  * @return int  The command exit code
  */
 private function dbRead($command, $args, &$output)
 {
     if (!isset(self::$socket)) {
         $socketPath = '/var/run/smwingsd.sock';
         $errno = 0;
         $errstr = '';
         self::$socket = $this->phpWrapper->fsockopen('unix://' . $socketPath, -1, $errno, $errstr);
         if (!is_resource(self::$socket)) {
             $this->getLog()->warning(sprintf("Invalid socket (%d): %s. Fall back to exec().", $errno, $errstr));
         }
     }
     if (!is_resource(self::$socket)) {
         return $this->dbExec($command, call_user_func_array(array($this, 'prepareArguments'), $args), $output);
     }
     // prepend the database name and command
     array_unshift($args, $this->db, $command);
     try {
         $this->sendMessage(self::$socket, 0x10, $args);
         if ($command === 'getjson') {
             $output = $this->recvMessage(self::$socket);
         } else {
             $output = json_decode($this->recvMessage(self::$socket), TRUE);
         }
     } catch (\Exception $ex) {
         $this->log->exception($ex);
         return 1;
     }
     return 0;
 }
 public function getRunningTasks()
 {
     $running = array();
     $pattern = '|' . sprintf(preg_quote(self::PTRACK_PATH_TEMPLATE, '|'), "(?P<taskId>[^.]+)") . '|';
     foreach ($this->phpWrapper->glob(sprintf(self::PTRACK_PATH_TEMPLATE, '*')) as $socketPath) {
         $matches = array();
         if (preg_match($pattern, $socketPath, $matches) && isset($matches['taskId'])) {
             try {
                 $task = $this->getTaskStatus($matches['taskId']);
             } catch (\RuntimeException $ex) {
                 $this->log->exception($ex);
                 $this->phpWrapper->unlink($socketPath);
                 continue;
             }
             $running[$matches['taskId']] = $task;
         }
     }
     return $running;
 }