function request($url, $post = false, $options = array())
{
$defaults = array('timeout' => 10, 'headers' => array(), 'encoding' => 'utf-8', 'agent' => self::agent());
$options = array_merge($defaults, $options);
$ch = curl_init();
$params = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => $options['encoding'], CURLOPT_USERAGENT => $options['agent'], CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => $options['timeout'], CURLOPT_TIMEOUT => $options['timeout'], CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false);
if (!empty($options['headers'])) {
$params[CURLOPT_HTTPHEADER] = $options['headers'];
}
if (!empty($post)) {
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $post;
}
curl_setopt_array($ch, $params);
$content = curl_exec($ch);
$error = curl_errno($ch);
$message = curl_error($ch);
$response = curl_getinfo($ch);
curl_close($ch);
$response['error'] = $error;
$response['message'] = $message;
$response['content'] = $content;
self::$response = $response;
if (a::get($response, 'error')) {
return array('status' => 'error', 'msg' => 'The remote request failed: ' . $response['message']);
}
if (a::get($response, 'http_code') >= 400) {
return array('status' => 'error', 'msg' => 'The remote request failed - code: ' . $response['http_code'], 'code' => $response['http_code']);
}
return $response;
}