It allows to run your simple web-apps in spawn-fcgi/php-fpm environment.
@return boolean|null - Success.
504028
public static function compatRunEmul()
    {
        Daemon::$compatMode = true;
        Daemon::initSettings();

        $argv = isset($_SERVER['CMD_ARGV']) ? $_SERVER['CMD_ARGV'] : '';

        $args = \PHPDaemon\Core\Bootstrap::getArgs($argv);

        if (isset($args[$k = 'configfile'])) {
            Daemon::$config[$k] = $args[$k];
        }

        if (!Daemon::$config->loadCmdLineArgs($args)) {
            $error = true;
        }

        if (isset(Daemon::$config->configfile->value) && !Daemon::loadConfig(Daemon::$config->configfile->value)) {
            $error = true;
        }

        if (!isset(Daemon::$config->path->value)) {
            exit('\'path\' is not defined');
        }

        if ($error) {
            exit;
        }

        $appResolver = require Daemon::$config->path->value;
        $appResolver->init();

        $req = new \stdClass;
        $req->attrs = new \stdClass;
        $req->attrs->request = $_REQUEST;
        $req->attrs->get = $_GET;
        $req->attrs->post = $_REQUEST;
        $req->attrs->cookie = $_REQUEST;
        $req->attrs->server = $_SERVER;
        $req->attrs->files = $_FILES;
        $req->attrs->session = isset($_SESSION) ? $_SESSION : null;
        $req->attrs->connId = 1;
        $req->attrs->trole = 'RESPONDER';
        $req->attrs->flags = 0;
        $req->attrs->id = 1;
        $req->attrs->paramsDone = true;
        $req->attrs->inputDone = true;
        $req = $appResolver->getRequest($req);

        while (true) {
            $ret = $req->call();

            if ($ret === 1) {
                return;
            }
        }
    }
778470
public function run()
    {
        if ($this->runningInConsole()) {
            $kernel = $kernel = static::make('ConsoleKernel');

            $input = new Input();
            $output = new Output();

            $status = $kernel->handle($input, $output);

            $kernel->terminate($input, $status);

            exit($status);
        }
        else {
            $kernel = static::make('HttpKernel');

            $request = Request::createFromGlobals();
            $request::enableHttpMethodParameterOverride();
            $request->enableHttpRequestParameterOverride();
            $response = $kernel->handle($request);

            $response->send();

            $kernel->terminate($request, $response);
        }

        return true;
    }
777462
public static function exec()
    {
        if (self::$state > 0) {
            return null;
        }

        self::$state = 1;

        self::trigger('init');

        if (self::env('maintenance')) {
            self::$state = 4;
            self::stop(503);
        }

        self::trigger('changestatus', array(\UtilsStatusCode(), null));

        $resp = Route::get();

        if (is_integer($resp)) {
            self::$state = 5;
            self::stop($resp, 'Invalid route');
        }

        $callback = $resp['callback'];

        if (!$callback instanceof \Closure) {
            $parsed = explode(':', $callback, 2);

            $callback = '\\Controller\\' . strtr($parsed[0], '.', '\\');
            $callback = array(new $callback, $parsed[1]);
        }

        $output = call_user_func_array($callback, $resp['args']);

        if (class_exists('\\Inphinit\\Http\\Response', false)) {
            Response::dispatch();
        }

        if (class_exists('\\Inphinit\\Viewing\\View', false)) {
            View::dispatch();
        }

        if (self::$state < 2) {
            self::$state = 2;
        }

        self::trigger('ready');

        if ($output || is_numeric($output)) {
            echo $output;
        }

        if (self::$state < 3) {
            self::$state = 3;
        }

        self::trigger('finish');

        if (self::$state < 4) {
            self::$state = 4;
        }
    }
575076
public function execute()
    {
        $success = false;

        try {
            $file = $this->getDirectory() . DIRECTORY_SEPARATOR . $this->getFilename();
            $phar = new PHPPhar($file, 0, $this->getFilename());
            $phar->buildFromDirectory($this->getPHPCI()->buildPath, $this->getRegExp());

            $stub = $this->getStubContent();
            if ($stub) {
                $phar->setStub($stub);
            }

            $success = true;
        } catch (Exception $e) {
            $this->getPHPCI()->log(Lang::get('phar_internal_error'));
            $this->getPHPCI()->log($e->getMessage());
        }

        return $success;
    }
924387
public function run()
    {
        $this->connect();

        // tell server we want to listen
        $this->connection->writeText('{ "action" : "listen" }');

        while (!$this->moribund) {

            $read = array($this->connection->getSocket()->getRawSocket());

            // Suppressing warnings for stream_select() because it will raise
            // a warning if interrupted by a signal.
            $result = @stream_select(
                $read,
                $write = null,
                $except = null,
                null
            );

            if ($result === false || $result < 1) {
                continue;
            }

            $moribund = false;

            // check if server closed connection
            $bytes = $this->connection->getSocket()->peek(1);

            if (mb_strlen($bytes, '8bit') === 0) {
                $this->log(
                    'server closed connection.' . PHP_EOL,
                    Net_Notifier_Logger::VERBOSITY_CLIENT
                );

                $moribund = true;
            }

            try {

                if ($this->connection->read(Net_Notifier_Client::READ_BUFFER_LENGTH)) {

                    if ($this->connection->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSING) {

                        $messages = $this->connection->getTextMessages();
                        foreach ($messages as $message) {
                            if (mb_strlen($message, '8bit') > 0) {
                                $this->log(
                                    sprintf(
                                        'received message: "%s"' . PHP_EOL,
                                        $message
                                    ),
                                    Net_Notifier_Logger::VERBOSITY_MESSAGES
                                );
                                $this->handleMessage($message);
                            }
                        }
                    }

                } else {

                    $this->log(
                        'got a message chunk from server' . PHP_EOL,
                        Net_Notifier_Logger::VERBOSITY_CLIENT
                    );

                }

            } catch (Net_Notifier_WebSocket_HandshakeFailureException $e) {
                $this->log(
                    sprintf(
                        'failed server handshake: %s' . PHP_EOL,
                        $e->getMessage()
                    ),
                    Net_Notifier_Logger::VERBOSITY_CLIENT
                );
            }

            if ($moribund) {
                $this->connection->close();
                break;
            }

        }

        if ($this->connection->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSING) {
            $this->disconnect();
        }
    }
625522
public function run()
    {
        try {
            $this->initWebSocketServer()->run();

            return true;
        } catch (Exception\Quit $e) {
            $this->getLogger()->success(
                $e->getMessage()
            );

            return true;
        } catch (\Exception $e) {
            $traces = array_reverse(explode(PHP_EOL, $e->getTraceAsString()));

            foreach ($traces as $key => $trace) {
                $trace = explode(' ', $trace, 2);

                $traces[$key] = sprintf(
                    '#%s > %s',
                    str_pad($key + 1, strlen(count($traces)), '0', STR_PAD_LEFT),
                    $trace[1]
                );
            }

            $this->getLogger()->error(
                "%s: %s\n%s",
                get_class($e),
                $e->getMessage(),
                implode("\n", $traces)
            );

            return false;
        }
    }
1196175
public function execute()
    {
        if (empty($this->xmlConfigFile) && empty($this->directory)) {
            $this->phpci->logFailure('Neither configuration file nor test directory found.');
            return false;
        }

        $success = true;

        $this->phpci->logExecOutput(false);

        // Run any config files first. This can be either a single value or an array.
        if ($this->xmlConfigFile !== null) {
            $success &= $this->runConfigFile($this->xmlConfigFile);
        }

        // Run any dirs next. Again this can be either a single value or an array.
        if ($this->directory !== null) {
            $success &= $this->runDir($this->directory);
        }

        $tapString = $this->phpci->getLastOutput();
        $tapString = mb_convert_encoding($tapString, "UTF-8", "ISO-8859-1");

        try {
            $tapParser = new TapParser($tapString);
            $output = $tapParser->parse();
        } catch (\Exception $ex) {
            $this->phpci->logFailure($tapString);
            throw $ex;
        }

        $failures = $tapParser->getTotalFailures();

        $this->build->storeMeta('phpunit-errors', $failures);
        $this->build->storeMeta('phpunit-data', $output);

        $this->phpci->logExecOutput(true);

        return $success;
    }
183056
public function execute()
    {
        $msg = $this->phpci->interpolate($this->message);

        if (empty($this->server) || empty($this->room) || empty($this->nick)) {
            $this->phpci->logFailure(Lang::get('irc_settings'));
        }

        if (empty($this->port)) {
            $this->port = 6667;
        }

        $sock = fsockopen($this->server, $this->port);
        stream_set_timeout($sock, 1);

        $connectCommands = array(
            'USER ' . $this->nick . ' 0 * :' . $this->nick,
            'NICK ' . $this->nick,
        );
        $this->executeIrcCommands($sock, $connectCommands);
        $this->executeIrcCommand($sock, 'JOIN ' . $this->room);
        $this->executeIrcCommand($sock, 'PRIVMSG ' . $this->room . ' :' . $msg);

        fclose($sock);

        return true;
    }
259340
public function run()
    {
        $result = null;
        $this->hook->attach('cron.run.before', $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        ini_set('max_execution_time', 0);
        register_shutdown_function(array($this, 'shutdownHandler'));

        $this->logger->log('cron', 'Cron has started', 'info');

        try {
            $result = $this->process();
        } catch (Exception $ex) {
            $this->logger->log('cron', $ex->getMessage(), 'danger', false);
            $result = false;
        }

        $this->hook->attach('cron.run.after', $result, $this);
        $this->config->set('cron_last_run', GC_TIME);

        return (bool) $result;
    }
500535
public function run()
    {
        if (! $this->runPreSearch()) {
            return $this->value;
        }

        if (! preg_match('/%([0-9a-fA-F]{2})/U', $this->value)) {
            return $this->value;
        }
        //keep nullbyte to be detected later
        $this->value = str_replace('%00', '[sh_null]', $this->value);
        $this->value = rawurldecode($this->value);
        $this->value = str_replace('[sh_null]', '%00', $this->value);

        return $this->value;
    }
564875
public function run()
	{
		$this->say("Copying CLI files " . $this->source);

		if (!file_exists($this->source))
		{
			$this->say("Folder " . $this->source . " does not exist!");

			return true;
		}

		$this->prepareDirectory();

		$map = $this->copyTarget($this->source, $this->target);

		$this->setResultFiles($map);

		return true;
	}
429753
public function systype() {
		$this->connectIfNeeded();
		$res = @ftp_systype($this->handle);
		return $res == null || $res == false ? 'UNIX' : $res;
	}
495780
public function execute()
    {
        $path  = $this->phpci->buildPath;
        $build = $this->build;

        if ($this->directory == $path) {
            return false;
        }

        $filename = str_replace('%build.commit%', $build->getCommitId(), $this->filename);
        $filename = str_replace('%build.id%', $build->getId(), $filename);
        $filename = str_replace('%build.branch%', $build->getBranch(), $filename);
        $filename = str_replace('%project.title%', $build->getProject()->getTitle(), $filename);
        $filename = str_replace('%date%', date('Y-m-d'), $filename);
        $filename = str_replace('%time%', date('Hi'), $filename);
        $filename = preg_replace('/([^a-zA-Z0-9_-]+)/', '', $filename);

        $curdir = getcwd();
        chdir($this->phpci->buildPath);

        if (!is_array($this->format)) {
            $this->format = array($this->format);
        }

        foreach ($this->format as $format) {
            switch ($format) {
                case 'tar':
                    $cmd = 'tar cfz "%s/%s.tar.gz" ./*';
                    break;
                default:
                case 'zip':
                    $cmd = 'zip -rq "%s/%s.zip" ./*';
                    break;
            }

            $success = $this->phpci->executeCommand($cmd, $this->directory, $filename);
        }

        chdir($curdir);

        return $success;
    }
15217
public function run()
    {
        if ($this->driver === null || (is_array($this->driver) && !isset($this->driver['__class']))) {
            $this->driver['__class'] = GdDriver::class;
        }

        $this->driver = $this->app->ensureObject($this->driver, DriverInterface::class);

        if ($this->app->request->getQueryParam(self::REFRESH_GET_VAR) !== null) {
            // AJAX request for regenerating code
            $code = $this->getVerifyCode(true);
            $this->app->response->format = Response::FORMAT_JSON;
            return [
                'hash1' => $this->generateValidationHash($code),
                'hash2' => $this->generateValidationHash(strtolower($code)),
                // we add a random 'v' parameter so that FireFox can refresh the image
                // when src attribute of image tag is changed
                'url' => Url::to([$this->id, 'v' => uniqid()]),
            ];
        }

        $this->setHttpHeaders();
        $this->app->response->format = Response::FORMAT_RAW;

        return $this->driver->renderImage($this->getVerifyCode());
    }
111362
public function run()
	{
		$null = null;
		$this->db =& ConnectionManager::getDataSource($this->connection);
		$this->db->cacheSources = false;
		$this->db->begin($null);

		if (!isset($this->args[0]) || !in_array($this->args[0], array('insert', 'remove'))) {
			$this->out(__d('Auditable', 'Invalid option'));
			return $this->_displayHelp(null);
		}

		try {
			$this->_run($this->args[0]);
			$this->_clearCache();

		} catch (Exception $e) {
			$this->db->rollback($null);
			throw $e;
		}

		return $this->db->commit($null);

		$this->out(__d('Auditable', 'All tables are updated.'));
		$this->out('');
		return true;
	}
1154274
public function execute()
    {
        $sendxmpp = $this->phpci->findBinary('sendxmpp');

        /*
         * Without recipients we can't send notification
         */
        if (count($this->recipients) == 0) {
            return false;
        }

        /*
         * Try to build conf file
         */
        $config_file = $this->phpci->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc';
        if (is_null($this->findConfigFile())) {
            file_put_contents($config_file, $this->getConfigFormat());
            chmod($config_file, 0600);
        }

        /*
         * Enabled ssl for connection
         */
        $tls = '';
        if ($this->tls) {
            $tls = ' -t';
        }

        $message_file = $this->phpci->buildPath . DIRECTORY_SEPARATOR . uniqid('xmppmessage');
        if ($this->buildMessage($message_file) === false) {
            return false;
        }

        /*
         * Send XMPP notification for all recipients
         */
        $cmd = $sendxmpp . "%s -f %s -m %s %s";
        $recipients = implode(' ', $this->recipients);

        $success = $this->phpci->executeCommand($cmd, $tls, $config_file, $message_file, $recipients);

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

        /*
         * Remove temp message file
         */
        $this->phpci->executeCommand("rm -rf ".$message_file);

        return $success;
    }
663641
public function main()
    {

        // load the interval we want to scan the directory
        $interval = $this->getInterval();

        // load the deployment directory
        $directory = $this->getDirectory();

        // log the configured deployment directory
        $this->getSystemLogger()->debug(sprintf('Start watching directory %s', $directory));

        // load the deployment flag
        $deploymentFlag = $this->getDeploymentFlag();

        // wait until the server has been successfully started at least once
        while ($this->getLastSuccessfullyDeployment($deploymentFlag) === 0) {
            $this->getSystemLogger()->debug(sprintf('%s is waiting for first successful deployment ...', __CLASS__));
            sleep($interval);
        }

        // load the initial hash value of the deployment directory
        $oldHash = $this->getDirectoryHash($directory);

        // watch the deployment directory
        while (true) {
            // load the actual hash value for the deployment directory
            $newHash = $this->getDirectoryHash($directory);

            // log the found directory hash value
            $this->getSystemLogger()->debug(sprintf("Comparing directory hash %s (previous) : %s (actual)", $oldHash, $newHash));

            // compare the hash values, if not equal restart the appserver
            if ($oldHash !== $newHash) {
                // log that changes have been found
                $this->getSystemLogger()->debug(sprintf('Found changes in directory %s', $directory));

                // log the UNIX timestamp of the last successful deployment
                $lastSuccessfullDeployment = $this->getLastSuccessfullyDeployment($deploymentFlag);

                // restart the appserver
                $this->restart();

                // wait until deployment has been finished
                while ($lastSuccessfullDeployment == $this->getLastSuccessfullyDeployment($deploymentFlag)) {
                    sleep($interval);
                }

                // set the directory new hash value after successful deployment
                $oldHash = $this->getDirectoryHash($directory);

                // log that the appserver has been restarted successful
                $this->getSystemLogger()->debug('appserver has successfully been restarted');

            } else {
                // if no changes has been found, wait a second
                sleep($interval);
            }
        }
    }