You are here

function _eloqua_cron_get_curl_resource in Eloqua 6

Returns a configured Curl Resource for use

Return value

resource

1 call to _eloqua_cron_get_curl_resource()
_eloqua_cron in ./eloqua.cron.inc
Implementation of hook_cron()

File

./eloqua.cron.inc, line 119

Code

function _eloqua_cron_get_curl_resource($options = array()) {
  $ch = _eloqua_cron_get_curl_handle();
  if ($ch == NULL) {
    return NULL;
  }

  // Setting Options
  $curl_opts = array(
    CURLOPT_HEADER => 1,
    CURLOPT_POST => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_CONNECTTIMEOUT => 5,
    // TODO: TIMEOUT ADMIN SETTING
    CURLOPT_TIMEOUT => 5,
    // TODO: TIMEOUT ADMIN SETTING
    CURLOPT_URL => 'http://now.eloqua.com/e/f2.aspx',
  );
  $option_map = array(
    'post_fields' => CURLOPT_POSTFIELDS,
    'user_agent' => CURLOPT_USERAGENT,
    'http_headers' => CURLOPT_HTTPHEADER,
  );
  foreach ($option_map as $key => $curl_key) {
    if (array_key_exists($key, $options)) {
      $curl_opts[$curl_key] = $options[$key];
    }
  }
  $status = _eloqua_set_curl_opts($ch, $curl_opts);
  $error_msg = _eloqua_set_curl_get_error($status);
  if (!empty($error_msg)) {

    // Failed setting an option
    $message = t('Unable to set curl options. Skipping message. !options.');
    $params = array(
      '!options' => '<pre>' . $error_msg . '</pre>',
    );
    watchdog('eloqua', $message, $params, WATCHDOG_ERROR);
    curl_close($ch);
    $ch = NULL;
  }
  return $ch;
}