public function send() { $this->access->setMemory(function_exists('memory_get_peak_usage') ? memory_get_peak_usage() : NULL); $this->access->setTime(-1 * $this->access->getTime() + microtime(TRUE)); list($accessData, $encoding) = $this->encodeData((string) $this->access); Consumerr::log("Shutdown - data encoded with {$encoding}, data length " . strlen($accessData)); $sender = Consumerr::getConfiguration()->getSenderInstance(); Consumerr::log("Shutdown - will use " . get_class($sender) . " for sending data."); $sender->send(array($accessData), $encoding); Consumerr::log("Shutdown complete."); }
public function send($data, $encoding) { $header = array('appSecret' => 'X-Consumerr-secret: ' . $this->configuration->getToken(), 'X-Consumerr-Encoding: ' . $encoding); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->configuration->getApiEndpoint()); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_exec($ch); if ($this->configuration->getLogFile()) { //logging enabled if (curl_errno($ch) !== 0) { Consumerr::log("Transmission error - " . curl_error($ch)); } $info = curl_getinfo($ch); if ($info['http_code'] != 200) { Consumerr::log("Transmission error - API returned HTTP " . $info['http_code']); } } @curl_close($ch); }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaultOptions); if ($config['enable'] === NULL) { $config['enable'] = !$this->getContainerBuilder()->parameters['debugMode']; } if (!$config['enable']) { $this->enabled = FALSE; Consumerr::log('Nette Consumerr extension disabled by Neon configuration or detected debug mode.'); return; } if (!empty($config['log']) && is_bool($config['log'])) { $dir = isset($this->getContainerBuilder()->parameters['logDir']) ? $this->getContainerBuilder()->parameters['logDir'] : Debugger::$logDirectory; if ($dir) { $config['log'] = $dir . '/consumerr.log'; } } $builder->addDefinition($this->prefix('consumerr'))->setClass('Consumerr\\' . 'NetteConsumerr')->setAutowired(FALSE); $builder->addDefinition($this->prefix('configuration'))->setClass('Consumerr\\' . 'Configuration', array($config))->setAutowired(FALSE); /*if ($config['cache']['enable'] === TRUE) { $consumerr->addSetup('setCache'); }*/ }