function background_process_ass_get_server_status in Background Process 7.2
Same name and namespace in other branches
- 8 background_process_ass/background_process_ass.module \background_process_ass_get_server_status()
- 6 background_process_ass/background_process_ass.module \background_process_ass_get_server_status()
- 7 background_process_ass/background_process_ass.module \background_process_ass_get_server_status()
Get apache extended server status.
@staticvar $server_status Cached statically to avoid multiple requests to server-status.
Parameters
$name: Name of service host for server-status.
$auto: Load only idle workers, not entire server status.
$reload: Don't load from cache.
Return value
array Server status data.
2 calls to background_process_ass_get_server_status()
- background_process_ass_auto_unlock in background_process_ass/
background_process_ass.module - Unlock locked processes that aren't really running.
- background_process_ass_service_group_idle in background_process_ass/
background_process_ass.module - Determine host with most idle workers and claim it.
File
- background_process_ass/
background_process_ass.module, line 282 - @todo Implement admin interface. @todo Fix runtime check of running process.
Code
function background_process_ass_get_server_status($name, $auto = FALSE, $reload = FALSE) {
// Sanity check ...
if (!$name) {
return;
}
$service_hosts = variable_get('background_process_service_hosts', array());
if (empty($service_hosts[$name])) {
return;
}
$service_host = $service_hosts[$name];
// Static caching.
$cache =& drupal_static('background_process_ass_server_status', array());
if (!$reload && isset($cache[$name][$auto])) {
return $cache[$name][$auto];
}
$server_status = array();
$options = array();
if ($auto) {
$options['query']['auto'] = 1;
}
list($url, $headers) = background_process_build_request('', $name, $options);
$timestamp = time();
$response = drupal_http_request($url, array(
'headers' => $headers,
));
if ($response->code != 200) {
watchdog('bg_process', 'Could not acquire server status from %url - error: %error', array(
'%url' => $url,
'%error' => $response->error,
), WATCHDOG_ERROR);
return NULL;
}
// If "auto" only collect idle workers
if ($auto) {
preg_match('/IdleWorkers:\\s+(\\d+)/', $response->data, $matches);
$server_status = $matches[1];
}
else {
$tables = _background_process_ass_parse_table($response->data);
$dls = _background_process_ass_parse_definition_list($response->data);
$server_status = array(
'response' => $response,
'connections' => $tables[0],
'status' => $dls[1],
);
preg_match('/.*?,\\s+(\\d+-.*?-\\d+\\s+\\d+:\\d+:\\d+)/', $server_status['status']['Restart Time'], $matches);
// @hack Convert monthly names from Danish to English for strtotime() to work
str_replace('Maj', 'May', $matches[1]);
str_replace('May', 'Oct', $matches[1]);
$server_status['status']['Restart Timestamp'] = strtotime($matches[1]);
$server_status['status']['Current Timestamp'] = $timestamp;
}
$cache[$name][$auto] = $server_status;
return $server_status;
}