示例#1
0
 public final function execute()
 {
     $hasThreads = function_exists('pcntl_signal');
     if (!$hasThreads || Cli::getInstance()->isSimulation()) {
         flush();
         try {
             return $this->executeNoThread();
         } catch (Interrupt $e) {
             throw $e;
         } catch (Exception $e) {
             echo $e;
         }
         return;
     }
     pcntl_signal(SIGCHLD, SIG_IGN);
     $pid = pcntl_fork();
     if ($pid < 1) {
         $this->_run();
         posix_kill(posix_getpid(), 9);
         pcntl_waitpid(posix_getpid(), $temp = 0, WNOHANG);
         pcntl_wifexited($temp);
         exit;
         //Make sure we exit...
     } else {
         $this->pid = $pid;
     }
 }
示例#2
0
 /**
  * Stop script and outputs an error page in CLI mode
  * 
  * @param string    $type       Type of error (the error page title)
  * @param string    $message    Error message
  * @param array     $backtrace  Array of parsed backtrace
  * @return void
  */
 private function _showCliError($type, $message, $backtrace)
 {
     $cli = Cli::getInstance();
     $cli->printf('[' . $type . ']', 'red');
     $cli->printf(' -> ' . $message . PHP_EOL);
     $bt = $this->_parseBacktrace($backtrace);
     $nb = count($bt);
     foreach ($bt as $k => $line) {
         $cli->printf('[debug' . $nb-- . ']', 'cyan');
         $cli->printf(' -> ');
         if (isset($line['exception'])) {
             $cli->printf($line['exception']);
         } else {
             $cli->printf($line['function'] . '(' . $line['args'] . ')');
         }
         if (isset($line['line']) && isset($line['file'])) {
             $cli->printf(' / ' . $line['file'] . ' ln.' . $line['line']);
         }
         $cli->printf(PHP_EOL);
     }
     die;
 }
示例#3
0
<?php

define("ROOT", dirname(__FILE__));
error_reporting(0);
include ROOT . '/include/AutoLoad.php';
Cli::getInstance()->run($argc, $argv);
示例#4
0
            $this->request = $this->data['request'];
            $this->context = $this->data['context'];
            $this->settings = $this->data['settings'];
        }
    }
    public function isEnabled()
    {
        return $this->isEnabled;
    }
    public function getData()
    {
        return $this->data;
    }
    public function getRequest()
    {
        return $this->request;
    }
    public function getContext()
    {
        return $this->context;
    }
    public function getSettings()
    {
        return $this->settings;
    }
    private $data, $request, $context, $settings, $isEnabled;
    public static $instance = null;
}
if (Cli::getInstance($argv)->isEnabled()) {
    Graphene::getInstance()->start();
}
示例#5
0
文件: Cli.php 项目: hofmeister/Pimple
 public function stopDaemon($pidFile, $force = false)
 {
     $pid = @file_get_contents($pidFile);
     if (!$pid) {
         Cli::getInstance()->displayErrorAndExit('Pid file empty or not found!');
     }
     unlink($pidFile);
     if ($force) {
         $this->killPid($pid);
         $this->displayLine('Daemon stopped forcefully');
     } else {
         $i = 0;
         while (true) {
             if ($i > 60) {
                 $this->displayLine('Daemon could not be stopped gracefully');
                 $this->killPid($pid);
                 $this->displayLine('Daemon stopped forcefully');
                 break;
             }
             if (!$this->isPidAlive($pid)) {
                 $this->displayLine('Daemon stopped gracefully');
                 break;
             }
             $i++;
             sleep(1);
         }
     }
     return true;
 }
示例#6
0
<?php

//To be done - is to pre-compile a sites views
return;
require_once '../bootstrap.php';
Cli::getInstance()->setRequiredParams('path', 'base');
$path = Cli::getInstance()->getParam('path');
if (is_dir($path)) {
} else {
    if (is_file($path)) {
    } else {
        Cli::getInstance()->displayErrorAndExit('Not a valid file or directory: ' . $path);
    }
}