Example #1
0
 /**
  * (non-PHPdoc)
  * @see \Koldy\Log\Writer\AbstractLogWriter::processExtendedReports()
  */
 protected function processExtendedReports()
 {
     if (!isset($this->config['dump'])) {
         return;
     }
     $dump = $this->config['dump'];
     // 'speed', 'included_files', 'include_path', 'whitespace'
     if (in_array('speed', $dump)) {
         $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] . '=' . Application::getUri() : 'CLI=' . Application::getCliName();
         $executedIn = Application::getRequestExecutionTime();
         $this->logMessage('notice', $method . ' LOADED IN ' . $executedIn . 'ms, ' . count(get_included_files()) . ' files');
     }
     if (in_array('included_files', $dump)) {
         $this->logMessage('notice', print_r(get_included_files(), true));
     }
     if (in_array('include_path', $dump)) {
         $this->logMessage('notice', print_r(explode(':', get_include_path()), true));
     }
     if (in_array('whitespace', $dump)) {
         $this->logMessage('notice', "----------\n\n\n");
     }
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see \Koldy\Application\Route\AbstractRoute::exec()
  */
 public function exec()
 {
     if (method_exists($this->controllerInstance, 'before')) {
         $response = $this->controllerInstance->before();
         // if "before" method returns anything, then we should not continue
         if ($response !== null) {
             return $response;
         }
     }
     $method = $this->getActionMethod();
     if (method_exists($this->controllerInstance, $method) || method_exists($this->controllerInstance, '__call')) {
         // get the return value of your method (json, xml, view object, download, string or nothing)
         return $this->controllerInstance->{$method}();
     } else {
         // the method we need doesn't exists, so, there is nothing we can do about it any more
         Log::notice("Can not find method={$method} in class={$this->getControllerClass()} on path={$this->controllerPath} for URI=" . Application::getUri());
         static::error(404);
     }
 }
 /**
  * Send e-mail report if system detected that e-mail should be sent
  * 
  * @return boolean|null true if mail was sent and null if mail shouldn't be sent
  */
 protected function sendEmailReport()
 {
     if ($this->emailReport === true && $this->config['email'] !== null) {
         $body = implode('', $this->messages);
         /* this doesn't have sense any more :::
         			$body .= "\n\n---------- debug_backtrace:\n";
         
         			foreach (debug_backtrace() as $r) {
         				if (isset($r['file']) && isset($r['line'])) {
         					$body .= "{$r['file']}:{$r['line']} ";
         				}
         
         				if (isset($r['function'])) {
         					$body .= "{$r['function']} ";
         				}
         
         				if (isset($r['args'])) {
         					$body .= implode(', ', $r['args']);
         				}
         
         				$body .= "\n";
         			}
         			*/
         $body .= "\n----------\n";
         $body .= sprintf("server: %s (%s)\n", Request::serverIp(), Request::hostName());
         if (PHP_SAPI != 'cli') {
             $body .= 'URI: ' . $_SERVER['REQUEST_METHOD'] . '=' . Application::getConfig('application', 'site_url') . Application::getUri() . "\n";
             $body .= sprintf("User IP: %s (%s)%s", Request::ip(), Request::host(), Request::hasProxy() ? sprintf(" via %s for %s\n", Request::proxySignature(), Request::httpXForwardedFor()) : "\n");
             $body .= sprintf("UAS: %s\n", isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'no user agent set');
         } else {
             $body .= 'CLI Name: ' . Application::getCliName() . "\n";
             $body .= 'CLI Script: ' . Application::getCliScript() . "\n";
             $params = Cli::getParameters();
             if (count($params) > 0) {
                 $body .= 'CLI Params: ' . print_r($params, true) . "\n";
             }
         }
         $body .= sprintf("Server load: %s\n", Server::getServerLoad());
         $peak = memory_get_peak_usage(true);
         $memoryLimit = ini_get('memory_limit');
         $body .= sprintf("Memory: %s; peak: %s; limit: %s; spent: %s%%\n", Convert::bytesToString(memory_get_usage(true)), Convert::bytesToString($peak), $memoryLimit, $memoryLimit !== false && $memoryLimit > 0 ? round($peak * 100 / Convert::stringToBytes($memoryLimit), 2) : 'null');
         $body .= sprintf("included files: %s\n", print_r(get_included_files(), true));
         $mail = Mail::create();
         $mail->from('alert@' . Request::hostName(), Request::hostName())->subject('Log report')->body($body);
         if (!is_array($this->config['email']) && strpos($this->config['email'], ',') !== false) {
             $this->config['email'] = explode(',', $this->config['email']);
         }
         if (is_array($this->config['email'])) {
             foreach ($this->config['email'] as $toEmail) {
                 $mail->to(trim($toEmail));
             }
         } else {
             $mail->to(trim($this->config['email']));
         }
         if (!$mail->send()) {
             $this->error("Can not send alert mail to {$this->config['email']}: {$mail->getError()}\n{$mail->getException()->getTraceAsString()}");
             return false;
         }
         return true;
     }
     return null;
 }