You are here

function varnish_get_status in Varnish 7

Same name and namespace in other branches
  1. 8 varnish.module \varnish_get_status()
  2. 6 varnish.module \varnish_get_status()

Get the status (up/down) of each of the varnish servers.

Return value

array An array of server statuses, keyed by varnish terminal addresses. The status will be a numeric constant, either:

2 calls to varnish_get_status()
varnish_admin_settings_form in ./varnish.admin.inc
Menu callback for varnish admin settings.
varnish_requirements in ./varnish.install
Implements hook_requirements().

File

./varnish.module, line 248
Common functions used for the module.

Code

function varnish_get_status() {

  // Use a static-cache so this can be called repeatedly without incurring
  // socket-connects for each call.
  static $results = NULL;
  if (is_null($results)) {
    $results = array();
    $status = _varnish_terminal_run(array(
      'status',
    ));
    $terminals = explode(' ', variable_get('varnish_control_terminal', '127.0.0.1:6082'));
    foreach ($terminals as $terminal) {
      $stat = array_shift($status);
      $results[$terminal] = $stat['status']['code'] == 200 ? VARNISH_SERVER_STATUS_UP : VARNISH_SERVER_STATUS_DOWN;
    }
  }
  return $results;
}