/** * Instantiate a probe object. * * @param string $query An URL-encoded string that configures the probe. Part of the string is signed. * @param string $serverId An id that is given to the agent for signature impersonation. * @param string $serverToken The token associated to $serverId. * @param string $agentSocket The URL where profiles will be written (directory, socket or TCP destination). * * @api */ public function __construct($query, $serverId = null, $serverToken = null, $agentSocket = null) { if (false === self::$defaultAgentSocket) { if ('Darwin' === PHP_OS) { $defaultAgentSocket = '/usr/local/var/run/blackfire-agent.sock'; } else { $defaultAgentSocket = '/var/run/blackfire/agent.sock'; } if (!file_exists($defaultAgentSocket)) { self::$defaultAgentSocket = null; } else { self::$defaultAgentSocket = 'unix://' . $defaultAgentSocket; } } $this->seqId = self::$nextSeqId++; $query = preg_split('/(?:^|&)signature=(.+?)(?:&|$)/', $query, 2, PREG_SPLIT_DELIM_CAPTURE); list($this->challenge, $this->signature, $args) = $query + array(1 => '', ''); $this->signature = rawurldecode($this->signature); parse_str($args, $args); parse_str($this->challenge, $this->signedArgs); $query = array('BLACKFIRE_SERVER_ID' => get_cfg_var('blackfire.server_id') ?: null, 'BLACKFIRE_SERVER_TOKEN' => get_cfg_var('blackfire.server_token') ?: null, 'BLACKFIRE_AGENT_SOCKET' => get_cfg_var('blackfire.agent_socket') ?: null, 'BLACKFIRE_AGENT_TIMEOUT' => get_cfg_var('blackfire.agent_timeout') ?: null, 'BLACKFIRE_LOG_LEVEL' => get_cfg_var('blackfire.log_level') ?: null, 'BLACKFIRE_LOG_FILE' => get_cfg_var('blackfire.log_file') ?: null); foreach ($query as $k => $v) { if (isset($_SERVER[$k])) { $query[$k] = $_SERVER[$k]; } } $this->serverId = $serverId ? $serverId : $query['BLACKFIRE_SERVER_ID']; $this->serverToken = $serverToken ? $serverToken : $query['BLACKFIRE_SERVER_TOKEN']; $this->agentSocket = $agentSocket; $this->agentSocket or $this->agentSocket = $query['BLACKFIRE_AGENT_SOCKET']; $this->agentSocket or $this->agentSocket = self::$defaultAgentSocket; $this->agentSocket or $this->agentSocket = ini_get('uprofiler.output_dir'); $this->agentSocket or $this->agentSocket = ini_get('xhprof.output_dir'); $this->agentTimeout = 1000000 * $query['BLACKFIRE_AGENT_TIMEOUT']; $this->agentTimeout or $this->agentTimeout = 250000; $query['BLACKFIRE_LOG_LEVEL'] and $this->logLevel = $query['BLACKFIRE_LOG_LEVEL']; $query['BLACKFIRE_LOG_FILE'] and $this->logFile = $query['BLACKFIRE_LOG_FILE']; $this->aggregSamples = isset($args['aggreg_samples']) && is_string($args['aggreg_samples']) ? max((int) $args['aggreg_samples'], 1) : 1; if ($this->logFile && strpos($this->logFile, '://') === false) { $this->logFile = 'file://' . $this->logFile; } elseif (!$this->logFile) { $this->logFile = 'php://stderr'; } empty($args['flag_cpu']) or $this->flags |= UPROFILER_FLAGS_CPU; empty($args['flag_memory']) or $this->flags |= UPROFILER_FLAGS_MEMORY; empty($args['flag_no_builtins']) or $this->flags |= UPROFILER_FLAGS_NO_BUILTINS; $this->options['blackfire_yml'] = !empty($args['flag_yml']); if (function_exists('uprofiler_enable')) { $this->profiler = 'uprofiler'; } elseif (function_exists('xhprof_enable')) { $this->profiler = 'xhprof'; } if ($this->logLevel >= 4) { $this->debug('New probe instanciated'); foreach ($this as $k => $v) { if ('options' !== $k && 'signedArgs' !== $k) { if ('' !== ($v = (string) $v)) { $this->debug(' ' . $k . ': ' . $v); } } } } }