You are here

function apachesolr_stats_exit in Apache Solr Statistics 6

Same name and namespace in other branches
  1. 6.3 apachesolr_stats.module \apachesolr_stats_exit()
  2. 7 apachesolr_stats.module \apachesolr_stats_exit()

Implementation of hook_exit().

This is the spot where actual logging takes place.

File

./apachesolr_stats.module, line 147
Keeps and reports statistics about Apache Solr usage and performance.

Code

function apachesolr_stats_exit() {
  if (!variable_get('apachesolr_stats_enabled', 0)) {
    return;
  }

  // Apparently there can be cases where some modules aren't loaded.
  if (!function_exists('apachesolr_has_searched')) {
    return;
  }

  // Ignore certain IPs
  $ignore_list = variable_get('apachesolr_stats_ignore_ip_list', '');
  if ($ignore_list) {
    $ips_to_ignore = preg_split('/[\\s]+/', $ignore_list);
    $request_ip_address = ip_address();
    foreach ($ips_to_ignore as $ip) {
      if ($ip != "" && strpos($request_ip_address, $ip) === 0) {
        return;
      }
    }
  }
  global $user;
  $roles_ignore_list = variable_get('apachesolr_stats_ignore_role_list', array());
  $test = array_intersect(array_keys($user->roles), array_values($roles_ignore_list));
  if (count($test) > 0) {
    return;
  }
  if (!apachesolr_has_searched()) {
    return;
  }
  $response = apachesolr_static_response_cache();
  $query = apachesolr_current_query();
  $url_queryvalues = $query
    ->get_url_queryvalues();
  $num_suggestions = 0;
  if (isset($response->spellcheck) && isset($response->spellcheck->suggestions) && $response->spellcheck->suggestions != NULL) {
    $num_suggestions = (int) get_object_vars($response->spellcheck->suggestions);
  }
  db_query("INSERT INTO {apachesolr_stats}\n    (timestamp, uid, sid, numfound, showed_suggestions, total_time, prepare_time, process_time, page, keywords, filters, sort, params)\n    VALUES\n    (%d, %d, '%s', %d, %d, %d, %d, %d, '%s', '%s','%s','%s','%s')", time(), $user->uid, session_id(), $response->response->numFound, $num_suggestions, $response->debug->timing->time, $response->debug->timing->prepare->time, $response->debug->timing->process->time, isset($_GET['page']) ? $_GET['page'] : '', $query
    ->get_query_basic(), isset($url_queryvalues['filters']) ? $url_queryvalues['filters'] : '', isset($url_queryvalues['solrsort']) ? $url_queryvalues['solrsort'] : '', serialize($response->responseHeader->params));
  return;

  /*
  $times = array();
  $times['total']['total'] = $response->debug->timing->time;
  foreach (array('prepare', 'process') as $phase) {
    foreach($response->debug->timing->prepare as $key => $value) {
      if (is_object($value)) {
        $times[$phase][$key] = (int) $value->time;
      } else {
        $times[$phase]['total'] = (int) $value;
      }
    }
  }
  dsm($times);
  return;
  */
}