You are here

function varnish_requirements in Varnish 6

Same name and namespace in other branches
  1. 8 varnish.install \varnish_requirements()
  2. 5 varnish.module \varnish_requirements()
  3. 7 varnish.install \varnish_requirements()

Implementation of hook_requirements()

Ensure that varnish's connection is good.

File

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

Code

function varnish_requirements($phase) {
  if ($phase == 'runtime') {
    $requirements = array(
      'varnish' => array(),
    );
    $requirements['varnish']['title'] = t('Varnish status');

    // try a varnish admin connect, report results
    $status = _varnish_terminal_run(array(
      'status',
    ));
    $terminals = explode(' ', variable_get('varnish_control_terminal', '127.0.0.1:6082'));
    foreach ($terminals as $term) {
      list($server, $port) = explode(':', $term);
      $stat = array_shift($status);
      if ($stat['status']['code'] === FALSE) {
        $requirements['varnish']['value'] = t('Varnish connection broken');
        $requirements['varnish']['severity'] = REQUIREMENT_ERROR;
        $requirements['varnish']['description'] = t('The Varnish control terminal is not responding at %server on port %port.', array(
          '%server' => $server,
          '%port' => $port,
        ));
        return $requirements;
      }
      else {
        $requirements['varnish']['value'] = t('Varnish running. Observe more detailed statistics !link.', array(
          '!link' => l(t('here'), 'admin/reports/varnish'),
        ));
      }
    }
    return $requirements;
  }
}