protected function willRun() { parent::willRun(); // This stores unbounded amounts of log data; make it discard instead so // that daemons do not require unbounded amounts of memory. DarkConsoleErrorLogPluginAPI::enableDiscardMode(); $phabricator = phutil_get_library_root('phabricator'); $root = dirname($phabricator); require_once $root . '/scripts/__init_env__.php'; // Daemons may perform writes. AphrontWriteGuard::allowDangerousUnguardedWrites(true); }
public static function initializeScriptEnvironment() { self::initializeCommonEnvironment(); // NOTE: This is dangerous in general, but we know we're in a script context // and are not vulnerable to CSRF. AphrontWriteGuard::allowDangerousUnguardedWrites(true); // There are several places where we log information (about errors, events, // service calls, etc.) for analysis via DarkConsole or similar. These are // useful for web requests, but grow unboundedly in long-running scripts and // daemons. Discard data as it arrives in these cases. PhutilServiceProfiler::getInstance()->enableDiscardMode(); DarkConsoleErrorLogPluginAPI::enableDiscardMode(); DarkConsoleEventPluginAPI::enableDiscardMode(); }
* See the License for the specific language governing permissions and * limitations under the License. */ error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); $include_path = ini_get('include_path'); ini_set('include_path', $include_path . PATH_SEPARATOR . dirname(__FILE__) . '/../../'); @(include_once 'libphutil/scripts/__init_script__.php'); if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to " . "include the parent directory of libphutil/.\n"; exit(1); } phutil_load_library(dirname(__FILE__) . '/../src/'); // NOTE: This is dangerous in general, but we know we're in a script context and // are not vulnerable to CSRF. AphrontWriteGuard::allowDangerousUnguardedWrites(true); require_once dirname(dirname(__FILE__)) . '/conf/__init_conf__.php'; $env = isset($_SERVER['PHABRICATOR_ENV']) ? $_SERVER['PHABRICATOR_ENV'] : getenv('PHABRICATOR_ENV'); if (!$env) { echo phutil_console_wrap(phutil_console_format("**ERROR**: PHABRICATOR_ENV Not Set\n\n" . "Define the __PHABRICATOR_ENV__ environment variable before running " . "this script. You can do it on the command line like this:\n\n" . " \$ PHABRICATOR_ENV=__custom/myconfig__ %s ...\n\n" . "Replace __custom/myconfig__ with the path to your configuration file. " . "For more information, see the 'Configuration Guide' in the " . "Phabricator documentation.\n\n", $argv[0])); exit(1); } $conf = phabricator_read_config_file($env); $conf['phabricator.env'] = $env; PhabricatorEnv::setEnvConfig($conf); phutil_load_library('arcanist/src'); foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } PhutilErrorHandler::initialize(); PhabricatorEventEngine::initialize();
public function saveEvents() { if (!$this->isActive()) { return; } $events = $this->events; if (!$events) { return; } if ($this->sampleRate === null) { throw new PhutilInvalidStateException('setSampleRate'); } $this->addServiceEvents(); // Don't sample any of this stuff. $this->pauseMultimeter(); $use_scope = AphrontWriteGuard::isGuardActive(); if ($use_scope) { $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(true); } $caught = null; try { $this->writeEvents(); } catch (Exception $ex) { $caught = $ex; } if ($use_scope) { unset($unguarded); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(false); } $this->unpauseMultimeter(); if ($caught) { throw $caught; } }
private static function stopProfiler() { $data = xhprof_disable(); $data = @json_encode($data); self::$profilerRunning = false; // Since these happen on GET we can't do guarded writes. These also // sometimes happen after we've disposed of the write guard; in this // case we need to disable the whole mechanism. $use_scope = AphrontWriteGuard::isGuardActive(); if ($use_scope) { $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(true); } $caught = null; try { $file = call_user_func(array('PhabricatorFile', 'newFromFileData'), $data, array('mime-type' => 'application/xhprof', 'name' => 'profile.xhprof')); } catch (Exception $ex) { $caught = $ex; } if ($use_scope) { unset($unguarded); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(false); } if ($caught) { throw $caught; } self::$profileFilePHID = $file->getPHID(); }
public static final function resetSetupState() { $cache = PhabricatorCaches::getSetupCache(); $cache->deleteKey('phabricator.setup.issue-keys'); $server_cache = PhabricatorCaches::getServerStateCache(); $server_cache->deleteKey('phabricator.in-flight'); $use_scope = AphrontWriteGuard::isGuardActive(); if ($use_scope) { $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(true); } $caught = null; try { $db_cache = new PhabricatorKeyValueDatabaseCache(); $db_cache->deleteKey('phabricator.setup.issue-keys'); } catch (Exception $ex) { $caught = $ex; } if ($use_scope) { unset($unguarded); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(false); } if ($caught) { throw $caught; } }