You are here

function varnish_admin_settings_form in Varnish 5

Same name and namespace in other branches
  1. 6 varnish.admin.inc \varnish_admin_settings_form()
  2. 7 varnish.admin.inc \varnish_admin_settings_form()

Menu callback for varnish admin settings.

1 string reference to 'varnish_admin_settings_form'
varnish_menu in ./varnish.module
Implementation of hook_menu()

File

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

Code

function varnish_admin_settings_form() {
  $form = array();

  // Decide whether or not to flush caches on cron runs.
  $form['varnish_flush_cron'] = array(
    '#type' => 'radios',
    '#title' => t('Flush page cache on cron?'),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled (with respect for cache_lifetime)'),
    ),
    '#default_value' => variable_get('varnish_flush_cron', 0),
    '#description' => t('Internally Drupal will attempt to flush its page cache every time cron.php runs. This can mean too-frequent cache flushes if you have cron running frequently. NOTE: this cache flush is global!'),
  );
  if (!extension_loaded('sockets')) {
    drupal_set_message(t('Sockets extension not enabled. Varnish terminal communication configuration skipped.'), 'error');
    return system_settings_form($form);
  }

  // Begin socket-dependent configuration.
  $form['varnish_control_terminal_server'] = array(
    '#type' => 'textfield',
    '#title' => t('Varnish Control Terminal Server'),
    '#default_value' => variable_get('varnish_control_terminal_server', '127.0.0.1'),
    '#required' => TRUE,
    '#description' => t('Set this to the server IP or hostname that varnish runs on. This must be configured for Drupal to talk to Varnish.'),
  );
  $form['varnish_control_terminal_port'] = array(
    '#type' => 'textfield',
    '#title' => t('Varnish Control Terminal Server'),
    '#default_value' => variable_get('varnish_control_terminal_port', '6082'),
    '#required' => TRUE,
    '#description' => t('Set this to the port on which your varnish control terminal runs. This must be configured for Drupal to talk to Varnish.'),
  );
  $form['varnish_control_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Varnish Control Key'),
    '#default_value' => variable_get('varnish_control_key', ''),
    '#description' => t('Optional: if you have established a secret key for control terminal access, please put it here.'),
  );
  $form['varnish_cache_clear'] = array(
    '#type' => 'radios',
    '#title' => t('Varnish Cache Clearing'),
    '#options' => array(
      VARNISH_DEFAULT_CLEAR => t('Drupal Default'),
      VARNISH_NO_CLEAR => t('None'),
    ),
    '#default_value' => variable_get('varnish_cache_clear', VARNISH_DEFAULT_CLEAR),
    '#description' => t('What kind of cache clearing Varnish should utilize. "Drupal Default" will clear the entire Varnish page cache on node updates, comment updates/additions, and/or other cache flush events. "None" will allow stale pages to persist when nodes and comments are added, and all other Drupal-based cache clearing events (except for cron run varnish cache clearing if you have that enabled).'),
  );
  $form['varnish_stats'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#title' => t('Stats'),
  );
  if ($_GET['stats'] == 1) {
    $status = _varnish_terminal_run('stats', 50000);
    $form['varnish_stats']['#collapsed'] = FALSE;
  }
  else {
    $status = l(t('Fetch stats'), 'admin/settings/varnish', array(), 'stats=1');
    $form['varnish_stats']['#collapsed'] = TRUE;
  }
  $form['varnish_stats']['data'] = array(
    '#type' => 'markup',
    '#prefix' => '<pre>',
    '#suffic' => '</pre>',
    '#value' => $status,
  );
  return system_settings_form($form);
}