private static function initializeCommonEnvironment() { PhutilErrorHandler::initialize(); self::buildConfigurationSourceStack(); // Force a valid timezone. If both PHP and Phabricator configuration are // invalid, use UTC. $tz = PhabricatorEnv::getEnvConfig('phabricator.timezone'); if ($tz) { @date_default_timezone_set($tz); } $ok = @date_default_timezone_set(date_default_timezone_get()); if (!$ok) { date_default_timezone_set('UTC'); } // Prepend '/support/bin' and append any paths to $PATH if we need to. $env_path = getenv('PATH'); $phabricator_path = dirname(phutil_get_library_root('phabricator')); $support_path = $phabricator_path . '/support/bin'; $env_path = $support_path . PATH_SEPARATOR . $env_path; $append_dirs = PhabricatorEnv::getEnvConfig('environment.append-paths'); if (!empty($append_dirs)) { $append_path = implode(PATH_SEPARATOR, $append_dirs); $env_path = $env_path . PATH_SEPARATOR . $append_path; } putenv('PATH=' . $env_path); // Write this back into $_ENV, too, so ExecFuture picks it up when creating // subprocess environments. $_ENV['PATH'] = $env_path; PhabricatorEventEngine::initialize(); $translation = PhabricatorEnv::newObjectFromConfig('translation.provider'); PhutilTranslator::getInstance()->setLanguage($translation->getLanguage())->addTranslations($translation->getTranslations()); }
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(); // If possible, install a signal handler for SIGHUP which prints the current // backtrace out to a named file. This is particularly helpful in debugging // hung/spinning processes. if (function_exists('pcntl_signal')) { pcntl_signal(SIGHUP, '__phutil_signal_handler__'); } }
private static function initializeCommonEnvironment() { PhutilErrorHandler::initialize(); self::buildConfigurationSourceStack(); // Force a valid timezone. If both PHP and Phabricator configuration are // invalid, use UTC. $tz = self::getEnvConfig('phabricator.timezone'); if ($tz) { @date_default_timezone_set($tz); } $ok = @date_default_timezone_set(date_default_timezone_get()); if (!$ok) { date_default_timezone_set('UTC'); } // Prepend '/support/bin' and append any paths to $PATH if we need to. $env_path = getenv('PATH'); $phabricator_path = dirname(phutil_get_library_root('phabricator')); $support_path = $phabricator_path . '/support/bin'; $env_path = $support_path . PATH_SEPARATOR . $env_path; $append_dirs = self::getEnvConfig('environment.append-paths'); if (!empty($append_dirs)) { $append_path = implode(PATH_SEPARATOR, $append_dirs); $env_path = $env_path . PATH_SEPARATOR . $append_path; } putenv('PATH=' . $env_path); // Write this back into $_ENV, too, so ExecFuture picks it up when creating // subprocess environments. $_ENV['PATH'] = $env_path; // If an instance identifier is defined, write it into the environment so // it's available to subprocesses. $instance = self::getEnvConfig('cluster.instance'); if (strlen($instance)) { putenv('PHABRICATOR_INSTANCE=' . $instance); $_ENV['PHABRICATOR_INSTANCE'] = $instance; } PhabricatorEventEngine::initialize(); // TODO: Add a "locale.default" config option once we have some reasonable // defaults which aren't silly nonsense. self::setLocaleCode('en_US'); }
} // Append any paths to $PATH if we need to. $paths = PhabricatorEnv::getEnvConfig('environment.append-paths'); if (!empty($paths)) { $current_env_path = getenv('PATH'); $new_env_paths = implode(':', $paths); putenv('PATH=' . $current_env_path . ':' . $new_env_paths); } // This is the earliest we can get away with this, we need env config first. PhabricatorAccessLog::init(); $access_log = PhabricatorAccessLog::getLog(); if ($access_log) { $access_log->setData(array('R' => idx($_SERVER, 'HTTP_REFERER', '-'), 'r' => idx($_SERVER, 'REMOTE_ADDR', '-'), 'M' => idx($_SERVER, 'REQUEST_METHOD', '-'))); } DarkConsoleXHProfPluginAPI::hookProfiler(); PhutilErrorHandler::initialize(); PhutilErrorHandler::setErrorListener(array('DarkConsoleErrorLogPluginAPI', 'handleErrors')); foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } if (PhabricatorEnv::getEnvConfig('phabricator.setup')) { try { PhabricatorSetup::runSetup(); } catch (Exception $ex) { echo "EXCEPTION!\n"; echo $ex; } return; } phabricator_detect_bad_base_uri(); $translation = PhabricatorEnv::newObjectFromConfig('translation.provider');