You are here

function httprl_requirements in HTTP Parallel Request & Threading Library 7

Same name and namespace in other branches
  1. 6 httprl.install \httprl_requirements()

Implements hook_requirements().

File

./httprl.install, line 29
Handle HTTP Parallel Request Library installation and upgrade tasks.

Code

function httprl_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime' || $phase == 'install') {
    $function_list = array(
      'stream_socket_client',
      'stream_select',
      'stream_set_blocking',
      'stream_get_meta_data',
      'stream_socket_get_name',
    );

    // Check each function to make sure it exists.
    foreach ($function_list as $function_name) {
      if (!function_exists($function_name)) {
        $requirements['httprl_function_' . $function_name] = array(
          'title' => $t('HTTPRL'),
          'value' => $phase == 'install' ? FALSE : $function_name,
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('<a href="!url">%name()</a> is disabled on this server. Please contact your hosting provider and see if they can re-enable this function for you.', array(
            '!url' => 'http://php.net/' . str_replace('_', '-', $function_name),
            '%name' => $function_name,
          )),
        );
      }
    }
  }
  if ($phase == 'runtime') {

    // Check that the menu router item is working. If it is not working, the
    // rest of the tests below will be pointless.
    $item = menu_get_item('httprl_async_function_callback');
    if (empty($item['page_callback']) || strpos($item['page_callback'], 'httprl') === FALSE) {
      $requirements['httprl_callback'] = array(
        'title' => $t('HTTPRL - Menu Callback'),
        'severity' => REQUIREMENT_WARNING,
        'value' => $t('Flush your caches'),
        'description' => $t('You need to flush your menu cache. The background callback for httprl is not there.'),
      );
      return $requirements;
    }
    if (defined('VERSION') && substr(VERSION, 0, 1) >= 7 && httprl_variable_get('maintenance_mode', 0) || httprl_variable_get('site_offline', 0)) {
      if (empty($requirements)) {
        $requirements['httprl'] = array(
          'title' => $t('HTTPRL'),
          'severity' => REQUIREMENT_INFO,
          'value' => $phase == 'install' ? TRUE : $t('All the required functions are enabled, but non blocking requests can not be tested while the site is in maintenance mode.'),
        );
      }
      return $requirements;
    }

    // Test the non-blocking url.
    list($success, $msg_non_blocking) = httprl_install_http_test(2, FALSE);
    if (!$success) {

      // Test the blocking url.
      list($success, $msg_blocking) = httprl_install_http_test(2, TRUE);
      if (!$success) {

        // Test that drupal_http_request() works.
        list($success, $msg_core) = httprl_install_http_test(1);
        if (!$success) {
          $requirements['httprl_callback'] = array(
            'title' => $t('HTTPRL - Core'),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('drupal_http_request()'),
            'description' => $t('Your system or network configuration does not allow Drupal to access web pages. This could be due to your webserver configuration or PHP settings. Debug info: !debug <br />For more info go here: <a href="!link">"HTTP request status Fails" error</a>', array(
              '!link' => 'http://drupal.org/node/588186',
              '!debug' => httprl_pr($GLOBALS['_httprl']['install']['debug'], TRUE),
            )),
          );
          return $requirements;
        }
        $requirements['httprl_blocking'] = array(
          'title' => $t('HTTPRL - Blocking'),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('Problem with stream_select()'),
          'description' => $t('This server can not issue self http requests with stream_select(). Debug info: !debug <br />', array(
            '!debug' => httprl_pr($GLOBALS['_httprl']['install']['debug'], TRUE),
          )),
        );
        return $requirements;
      }
      $requirements['httprl_nonblocking'] = array(
        'title' => $t('HTTPRL - Non Blocking'),
        'severity' => REQUIREMENT_WARNING,
        'value' => $t('This server does not handle hanging connections.'),
        'description' => $t('Using non blocking mode on this server may not work correctly. Debug info: !debug <br />', array(
          '!debug' => httprl_pr($GLOBALS['_httprl']['install']['debug'], TRUE),
        )),
      );
    }
  }
  if (!empty($msg_non_blocking)) {
    $requirements['httprl_settings_change_a'] = array(
      'title' => $t('HTTPRL - Settings'),
      'severity' => REQUIREMENT_WARNING,
      'value' => $t('The current configuration does not work.'),
      'description' => $msg_non_blocking,
    );
  }
  if (!empty($msg_blocking)) {
    $requirements['httprl_settings_change_b'] = array(
      'title' => $t('HTTPRL - Settings'),
      'severity' => REQUIREMENT_WARNING,
      'value' => $t('The current configuration does not work.'),
      'description' => $msg_blocking,
    );
  }
  if (!empty($msg_core)) {
    $requirements['httprl_settings_change_c'] = array(
      'title' => $t('HTTPRL - Settings'),
      'severity' => REQUIREMENT_WARNING,
      'value' => $t('The current configuration does not work.'),
      'description' => $msg_core,
    );
  }
  if (empty($requirements)) {
    $requirements['httprl'] = array(
      'title' => $t('HTTPRL'),
      'severity' => REQUIREMENT_OK,
      'value' => $phase == 'install' ? TRUE : $t('All the required functions are enabled and non blocking requests are working.'),
    );
  }
  return $requirements;
}