Ejemplo n.º 1
0
 public static function initialize()
 {
     if (!self::$router) {
         $router = new self();
         // If pcntl_signal() does not exist (particularly, on Windows), just
         // don't install signal handlers.
         if (function_exists('pcntl_signal')) {
             pcntl_signal(SIGHUP, array($router, 'routeSignal'));
             pcntl_signal(SIGTERM, array($router, 'routeSignal'));
         }
         self::$router = $router;
     }
     return self::getRouter();
 }
Ejemplo n.º 2
0
 public final function __construct(array $argv)
 {
     $this->argv = $argv;
     $router = PhutilSignalRouter::getRouter();
     $handler_key = 'daemon.term';
     if (!$router->getHandler($handler_key)) {
         $handler = new PhutilCallbackSignalHandler(SIGTERM, __CLASS__ . '::onTermSignal');
         $router->installHandler($handler_key, $handler);
     }
     pcntl_signal(SIGINT, array($this, 'onGracefulSignal'));
     pcntl_signal(SIGUSR2, array($this, 'onNotifySignal'));
     // Without discard mode, this consumes unbounded amounts of memory. Keep
     // memory bounded.
     PhutilServiceProfiler::getInstance()->enableDiscardMode();
     $this->beginStdoutCapture();
 }
Ejemplo n.º 3
0
function __phutil_init_script__()
{
    // Adjust the runtime language configuration to be reasonable and inline with
    // expectations. We do this first, then load libraries.
    // There may be some kind of auto-prepend script configured which starts an
    // output buffer. Discard any such output buffers so messages can be sent to
    // stdout (if a user wants to capture output from a script, there are a large
    // number of ways they can accomplish it legitimately; historically, we ran
    // into this on only one install which had some bizarre configuration, but it
    // was difficult to diagnose because the symptom is "no messages of any
    // kind").
    while (ob_get_level() > 0) {
        ob_end_clean();
    }
    error_reporting(E_ALL | E_STRICT);
    $config_map = array('display_errors' => true, 'log_errors' => true, 'error_log' => null, 'xdebug.max_nesting_level' => PHP_INT_MAX, 'memory_limit' => -1);
    foreach ($config_map as $config_key => $config_value) {
        ini_set($config_key, $config_value);
    }
    if (!ini_get('date.timezone')) {
        // If the timezone isn't set, PHP issues a warning whenever you try to parse
        // a date (like those from Git or Mercurial logs), even if the date contains
        // timezone information (like "PST" or "-0700") which makes the
        // environmental timezone setting is completely irrelevant. We never rely on
        // the system timezone setting in any capacity, so prevent PHP from flipping
        // out by setting it to a safe default (UTC) if it isn't set to some other
        // value.
        date_default_timezone_set('UTC');
    }
    // Adjust `include_path`.
    ini_set('include_path', implode(PATH_SEPARATOR, array(dirname(dirname(__FILE__)) . '/externals/includes', ini_get('include_path'))));
    // Disable the insanely dangerous XML entity loader by default.
    if (function_exists('libxml_disable_entity_loader')) {
        libxml_disable_entity_loader(true);
    }
    // Now, load libphutil.
    $root = dirname(dirname(__FILE__));
    require_once $root . '/src/__phutil_library_init__.php';
    PhutilErrorHandler::initialize();
    $router = PhutilSignalRouter::initialize();
    $handler = new PhutilBacktraceSignalHandler();
    $router->installHandler('phutil.backtrace', $handler);
}