Prose\FromHost::getAllScreenSessions PHP Method

getAllScreenSessions() public method

public getAllScreenSessions ( ) : array
return array
    public function getAllScreenSessions()
    {
        // what are we doing?
        $log = usingLog()->startAction("get details about all screen sessions on host '{$this->args[0]}'");
        // are there any details?
        $cmd = "screen -ls";
        $result = usingHost($this->args[0])->runCommandAndIgnoreErrors($cmd);
        // NOTE:
        //
        // screen is not a well-behaved UNIX program, and its exit code
        // can be non-zero when everything is good
        if (empty($result->output)) {
            $msg = "unable to get list of screen sessions";
            $log->endAction($msg);
            return [];
        }
        // reduce the output down to a list of sessions
        $lines = explode("\n", $result->output);
        $lines = FilterForMatchingRegex::against($lines, "/[0-9]+.+\t/");
        if (empty($lines)) {
            $msg = "no screen processes running";
            $log->endAction($msg);
            return [];
        }
        $retval = [];
        foreach ($lines as $line) {
            $parts = explode('.', $line);
            $processDetails = new BaseObject();
            $processDetails->hostId = $this->args[0];
            $processDetails->type = 'screen';
            $processDetails->pid = trim($parts[0]);
            $processDetails->name = rtrim($parts[1]);
            $retval[] = $processDetails;
        }
        // all done
        $log->endAction("found " . count($retval) . " screen process(es)");
        // all done
        return $retval;
    }