You are here

function _acquia_lift_ping in Acquia Lift Connector 7.3

Pings a url and validates that the URL can be reached and shows messaging if it cannot.. NOTE: the drupal 8 version of this functionality also checks the response code (expecting 200) but this does not seem possible as responses here are correctly 403, 400, etc.

Parameters

string $type: The type of the URL to check

string $url: The URL to check

Return value

bool True if reachable, false otherwise.

1 call to _acquia_lift_ping()
acquia_lift_admin_form_submit in ./acquia_lift.admin.inc
Submit handler for the acquia_lift configuration form.

File

./acquia_lift.admin.inc, line 431
acquia_lift.admin.inc Provides functions needed for the admin UI.

Code

function _acquia_lift_ping($type, $url) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_NOBODY, TRUE);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_exec($ch);
  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  if ($status_code == 0) {
    drupal_set_message(t('Acquia Lift module could not reach the specified @type URL.', array(
      '@type' => $type,
    )), 'error');
    return FALSE;
  }
  return TRUE;
}