You are here

function varnish_get_status in Varnish 6

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

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

Return value

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

1 call to varnish_get_status()
varnish_admin_settings_form in ./varnish.admin.inc
Menu callback for varnish admin settings.

File

./varnish.module, line 235
varnish.module Provide drupal hooks for integration with the Varnish control layer.

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;
}