General server information
We will use the exec command here several times. In order tro prevent stop on failure, use $this->isExecAllowed().

@return array
190165
public function getServerInfo()
    {
        // init empty variables (can be filled if exec is allowed)
        $iMemTotal = $iMemFree = $sCpuModelName = $sCpuModel = $sCpuFreq = $iCpuCores = null;

        // fill, if exec is allowed
        if ($this->isExecAllowed()) {
            $iCpuAmnt = $this->_getCpuAmount();
            $iCpuMhz = $this->_getCpuMhz();
            $iBogo = $this->_getBogoMips();
            $iMemTotal = $this->_getMemoryTotal();
            $iMemFree = $this->_getMemoryFree();
            $sCpuModelName = $this->_getCpuModel();
            $sCpuModel = $iCpuAmnt . 'x ' . $sCpuModelName;
            $sCpuFreq = $iCpuMhz . ' MHz';

            // prevent "division by zero" error
            if ($iBogo && $iCpuMhz) {
                $iCpuCores = $iBogo / $iCpuMhz;
            }
        }

        $aServerInfo = [
            'Server OS'     => @php_uname('s'),
            'VM'            => $this->_getVirtualizationSystem(),
            'PHP'           => $this->_getPhpVersion(),
            'MySQL'         => $this->_getMySqlServerInfo(),
            'Apache'        => $this->_getApacheVersion(),
            'Disk total'    => $this->_getDiskTotalSpace(),
            'Disk free'     => $this->_getDiskFreeSpace(),
            'Memory total'  => $iMemTotal,
            'Memory free'   => $iMemFree,
            'CPU Model'     => $sCpuModel,
            'CPU frequency' => $sCpuFreq,
            'CPU cores'     => round($iCpuCores, 0),
        ];

        return $aServerInfo;
    }
671881
private function __getProcessOwner()
    {
        if (function_exists('posix_getpwuid')) {
            $a = posix_getpwuid(posix_getuid());

            return $a['name'];
        } else {
            $user = trim(exec('whoami', $o, $code));
            if ($code === 0) {
                return $user;
            }

            return false;
        }

        return false;
    }
944276
private function haltCheck(): ?array
    {
        // built-in http server
        if (PHP_SAPI == 'cli-server') {
            return null;
        }

        // check client host
        $hosts = $this->config->get('hosts');
        if ($hosts != null && (empty($_SERVER['HTTP_HOST']) ||
            !in_array($_SERVER['HTTP_HOST'], (array) $hosts))) {
            return ['hosts', '400 Bad Request'];
        }

        @ ['maxRequest' => $maxRequest,
           'allowEmptyUserAgent' => $allowEmptyUserAgent,
           'allowFileExtensionSniff' => $allowFileExtensionSniff] = $this->config->get('security');

        // check request count
        if ($maxRequest != null && count($_REQUEST) > $maxRequest) {
            return ['maxRequest', '429 Too Many Requests'];
        }

        // check user agent
        if ($allowEmptyUserAgent === false && (empty($_SERVER['HTTP_USER_AGENT']) ||
            trim($_SERVER['HTTP_USER_AGENT']) == '')) {
            return ['allowEmptyUserAgent', '400 Bad Request'];
        }

        // check file extension
        if ($allowFileExtensionSniff === false &&
            preg_match('~\.(?:p[hyl]p?|rb|cgi|cf[mc]|p(?:pl|lx|erl)|aspx?)$~i',
                (string) parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
            return ['allowFileExtensionSniff', '400 Bad Request'];
        }

        // check service load
        $loadAvg = $this->config->get('loadAvg');
        if ($loadAvg != null && sys_getloadavg()[0] > $loadAvg) {
            return ['loadAvg', '503 Service Unavailable'];
        }

        return null;
    }
669768
protected function _exec() {
        $response = curl_exec($this->_ch);
        $this->_last_info = curl_getinfo($this->_ch);
        $error = curl_error( $this->_ch );
        if ( $error ) {
            throw new \Exception($error);
        }

        return $response;
    }
349918
public function getAvailableExtensions()
    {
        $returnValue = array();
		$dir = new DirectoryIterator(ROOT_PATH);
		foreach ($dir as $fileinfo) {
			if ($fileinfo->isDir() && !$fileinfo->isDot() && substr($fileinfo->getBasename(), 0, 1) != '.') {
				$extId = $fileinfo->getBasename();
				if (!in_array($extId, self::$RESERVED_WORDS) && !$this->isInstalled($extId)) {
    				try {
    					$ext = $this->getExtensionById($extId);
    					$returnValue[] = $ext;
    				} catch (common_ext_ExtensionException $exception) {
    					common_Logger::d($extId.' is not an extension');
    				}
				}
			}
		}
		
		return $returnValue;
    }
875815
public function getSqlQueriesToExecute()
    {
        $queries = array();
        $classNames = array();

        foreach ($this->componentsWithUpdateFile as $componentName => $componentUpdateInfo) {
            foreach ($componentUpdateInfo as $file => $fileVersion) {
                require_once $file; // prefixed by PIWIK_INCLUDE_PATH

                $className = $this->getUpdateClassName($componentName, $fileVersion);
                if (!class_exists($className, false)) {
                    throw new \Exception("The class $className was not found in $file");
                }

                if (in_array($className, $classNames)) {
                    continue; // prevent from getting updates from Piwik\Columns\Updater multiple times
                }

                $classNames[] = $className;

                /** @var Updates $update */
                $update = StaticContainer::getContainer()->make($className);
                $migrationsForComponent = $update->getMigrations($this);
                foreach ($migrationsForComponent as $index => $migration) {
                    $migration = $this->keepBcForOldMigrationQueryFormat($index, $migration);
                    $queries[] = $migration;
                }
                $this->hasMajorDbUpdate = $this->hasMajorDbUpdate || call_user_func(array($className, 'isMajorUpdate'));
            }
        }
        return $queries;
    }
178938
public function getMetaData()
    {
        if (count($this->command) == 0) {
            return ['console' => [
                'Command' => 'Command could not be retrieved', ],
            ];
        }
        $commandString = implode(' ', $this->command);
        $primaryCommand = $this->command[0];
        $arguments = [];
        $options = [];
        foreach (array_slice($this->command, 1) as $arg) {
            if (isset($arg[0]) && $arg[0] === '-') {
                $options[] = $arg;
            } else {
                $arguments[] = $arg;
            }
        }
        $data = [
            'Input' => $commandString,
            'Command' => $primaryCommand,
            'Arguments' => $arguments,
            'Options' => $options,
        ];

        return ['console' => $data];
    }
88232
public function actionStopExecutable()
    {
        $rr = new RequestResponse();
        if ($rr->isRequestAjaxPost()) {
            $stoppedLong = CmsAgent::stopLongExecutable(0);
            $rr->message = \Yii::t('skeeks/agent', 'Running agents stopped');
            $rr->success = true;
            return $rr;
        }
    }
956
public function process_approved_deletions() : array {
        $this->trace->output('Checking requirements');
        if (!$this->check_requirements()) {
            $this->trace->output('Requirements not met. Cannot process expired retentions.', 1);
            return [0, 0];
        }

        $this->trace->output('Fetching all approved and expired contexts for deletion.');
        $expiredcontexts = expired_context::get_records(['status' => expired_context::STATUS_APPROVED]);
        $this->trace->output('Done.', 1);
        $totalprocessed = 0;
        $usercount = 0;
        $coursecount = 0;
        foreach ($expiredcontexts as $expiredctx) {
            $context = \context::instance_by_id($expiredctx->get('contextid'), IGNORE_MISSING);

            if (empty($context)) {
                // Unable to process this request further.
                // We have no context to delete.
                $expiredctx->delete();
                continue;
            }

            $this->trace->output("Deleting data for " . $context->get_context_name(), 2);
            if ($this->delete_expired_context($expiredctx)) {
                $this->trace->output("Done.", 3);
                if ($context instanceof \context_user) {
                    $usercount++;
                } else {
                    $coursecount++;
                }

                $totalprocessed++;
                if ($totalprocessed >= $this->get_delete_limit()) {
                    break;
                }
            }
        }

        return [$coursecount, $usercount];
    }
735222
public function getExcluded(): array
    {
        $arr = [];
        foreach ($this->columns as $name => $column) {
            if ($column->isExcluded()) {
                $arr[] = $name;
            }
        }

        return $arr;
    }
749690
protected function notFound()
    {
        $closest   = [];
        $attempted = $this->argv[1];
        $available = \array_keys($this->commands() + $this->aliases);

        foreach ($available as $cmd) {
            $lev = \levenshtein($attempted, $cmd);
            if ($lev > 0 || $lev < 5) {
                $closest[$cmd] = $lev;
            }
        }

        $this->io()->error("Command $attempted not found", true);
        if ($closest) {
            \asort($closest);
            $closest = \key($closest);
            $this->io()->bgRed("Did you mean $closest?", true);
        }

        return ($this->onExit)(127);
    }
862438
public function get_extensions()
    {
        if ($this->exts)
            return $this->exts;

        if (!$this->sieve)
            return $this->_set_error(self::ERROR_INTERNAL);

        $ext = $this->sieve->getExtensions();

        if (is_a($ext, 'PEAR_Error')) {
            return array();
        }

        // we're working on lower-cased names
        $ext = array_map('strtolower', (array) $ext);

        if ($this->script) {
            $supported = $this->script->get_extensions();
            foreach ($ext as $idx => $ext_name)
                if (!in_array($ext_name, $supported))
                    unset($ext[$idx]);
        }

        return array_values($ext);
    }
753955
public function exec()
    {
        return $this->db->fetchAffected(
            $this->query->__toString(),
            $this->query->getBindValues()
        );
    }
875028
public function isExempt()
    {
        /*
         * This would grab the exempted routes from the maintenance.php config file
         *
         * An example of this file:
         * return [
         *   'exemptions' => [
         *     'user-groups' => [ 1, 2, 3 ],
         *   ],
         * ];
         */

        $exemptGroups = $this->app['config']->get('maintenancemode.exemptions.user-groups', []);
        $currentUser = $this->app['auth']->user();
        if(is_array($exemptGroups) && $currentUser !== null)
        {
            // Grab the current user group IDs
            $currentUserGroups = $currentUser->groups->modelKeys();

            // Check to see if the user is within this group
            if((is_array($currentUserGroups) && count(array_intersect($currentUserGroups, $exemptGroups))) ||
                !is_array($currentUserGroups) && in_array($currentUserGroups, $exemptGroups))
            {
                // The user matched the whitelist, they will NOT see the maintenance page
                return true;
            }
        }

        // The current user did not match the whitelist, therefore they MIGHT see the maintenance page (depending on other exemptions)
        return false;
    }
389316
public function exec() : self
    {
        $descSpec = [
            0 => ["pipe", "r"]
        ];
        foreach ($this->listener as $chanId => $listener) {
            $descSpec[$chanId] = ["pipe", "w"];
        }

        $this->proc = proc_open($this->cmd, $descSpec, $pipes);

        if ($this->proc === false)
            throw new \Exception("Unable to proc_open()");

        //print_r (proc_get_status($this->proc));

        foreach ($this->listener as $chanId => $listener) {
            stream_set_blocking($pipes[$chanId], 0);
        }
        $this->pipes = $pipes;
        return $this;
    }
959192
public function execute()
    {
        $ignore = '';
        if (count($this->ignore)) {
            $namesExclude = ' --names-exclude ';
            foreach ($this->ignore as $item) {
                // remove the trailing slash
                $item = rtrim($item, DIRECTORY_SEPARATOR);

                if (is_file(rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $item)) {
                    $ignoredFile = explode('/', $item);
                    $filesToIgnore[] = array_pop($ignoredFile);
                } else {
                    $ignore .= ' --exclude ' . $item;
                }
            }

            if (isset($filesToIgnore)) {
                $filesToIgnore = $namesExclude . implode(',', $filesToIgnore);
                $ignore = $ignore . $filesToIgnore;
            }
        }

        $phpcpd = $this->phpci->findBinary('phpcpd');

        $tmpfilename = tempnam('/tmp', 'phpcpd');

        $cmd = $phpcpd . ' --log-pmd "%s" %s "%s"';
        $success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path);

        print $this->phpci->getLastOutput();

        $errorCount = $this->processReport(file_get_contents($tmpfilename));
        $this->build->storeMeta('phpcpd-warnings', $errorCount);

        unlink($tmpfilename);

        return $success;
    }
549222
public function errorInfo()
	{
		return array
		(
			0 => $this->driver->getSQLState(),
			1 => $this->driver->getErrorCode(),
			2 => $this->driver->getLastMessage()
		);
	}