function background_process_ass_get_server_status in Background Process 8
Same name and namespace in other branches
- 6 background_process_ass/background_process_ass.module \background_process_ass_get_server_status()
- 7.2 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.
2 calls to background_process_ass_get_server_status()
- background_process_ass_auto_unlock in background_process_ass/
background_process_ass.module - Implements to Unlock locked processes that aren't really running.
- background_process_ass_service_group_idle in background_process_ass/
background_process_ass.module - Implements to Determine host with most idle workers and claim it.
File
- background_process_ass/
background_process_ass.module, line 195 - Implements Background Process Ass Module. @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 = \Drupal::config('background_process.settings')
->get('background_process_service_hosts');
if (empty($service_hosts[$name])) {
return;
}
// Static caching.
$cache =& drupal_static('background_process_ass_server_status', []);
if (!$reload && isset($cache[$name][$auto])) {
return $cache[$name][$auto];
}
$server_status = [];
$options = [];
if ($auto) {
$options['query']['auto'] = 1;
}
list($url, $headers) = background_process_build_request('', $name, $options);
$timestamp = time();
$client = \Drupal::httpClient();
$response = $client
->createRequest('GET', $url);
$response
->addHeader('headers', $headers);
if ($response->code != 200) {
\Drupal::logger('bg_process')
->error('Could not acquire server status from %url - error: %error', [
'%url' => $url,
'%error' => $response->error,
]);
return NULL;
}
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 = [
'response' => $response,
'connections' => $tables[0],
'status' => $dls[1],
];
preg_match('/.*?,\\s+(\\d+-.*?-\\d+\\s+\\d+:\\d+:\\d+)/', $server_status['status']['Restart Time'], $matches);
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;
}