/** * Returns a global singleton and enables it by default. * * Uses the X-Blackfire-Query HTTP header to create this singleton on its first use. * * Additionally, this function enables the probe, except when the just said string * contains an auto_enable=0 URL parameter. * * @return self * * @api */ public static function getMainInstance() { if (null !== self::$probe) { return self::$probe; } if (isset($_SERVER['HTTP_X_BLACKFIRE_QUERY'])) { $query = $_SERVER['HTTP_X_BLACKFIRE_QUERY']; } elseif (isset($_SERVER['BLACKFIRE_QUERY'])) { $query = $_SERVER['BLACKFIRE_QUERY']; } else { $query = ''; } self::$probe = new self($query); parse_str($query, $query); if (!isset($query['auto_enable']) || $query['auto_enable']) { if (self::$probe->isVerified()) { if (self::$probe->blackfireYmlAsked()) { self::$probe->info('blackfire.yml asked.'); $config = self::$probe->getConfiguration(); self::$probe->responseLine .= '&blackfire-yml-size=' . strlen($config); if (!headers_sent()) { header('X-' . self::$probe->getResponseLine()); } echo $config; exit(0); } self::$probe->autoEnabled = self::$probe->enable(); } } return self::$probe; }