function httprl_set_default_options in HTTP Parallel Request & Threading Library 6
Same name and namespace in other branches
- 7 httprl.module \httprl_set_default_options()
Set the default options in the $options array.
Parameters
array &$options: Array containing options.
1 call to httprl_set_default_options()
- httprl_request in ./
httprl.module - Queue up a HTTP request in httprl_send_request.
File
- ./
httprl.module, line 515 - HTTP Parallel Request Library module.
Code
function httprl_set_default_options(array &$options) {
global $base_root;
// Merge the default options.
$options += array(
'headers' => array(),
'method' => 'GET',
'data' => NULL,
'max_redirects' => 3,
'timeout' => httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT),
'dns_timeout' => httprl_variable_get('httprl_dns_timeout', HTTPRL_DNS_TIMEOUT),
'connect_timeout' => httprl_variable_get('httprl_connect_timeout', HTTPRL_CONNECT_TIMEOUT),
'ttfb_timeout' => httprl_variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT),
'context' => NULL,
'secure_socket_transport' => 'ssl',
'blocking' => TRUE,
'version' => '1.0',
'referrer' => FALSE,
'domain_connections' => 2,
'global_connections' => 128,
'global_timeout' => httprl_variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT),
'chunk_size_read' => 32768,
'chunk_size_write' => 1024,
'async_connect' => TRUE,
'ping_db' => 20,
'url_encoding' => array(),
);
// Adjust Time To First Byte Timeout if timeout is large and ttfb is default.
if ($options['timeout'] > httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) && $options['ttfb_timeout'] == httprl_variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT)) {
$options['ttfb_timeout'] = $options['timeout'] - max(1, httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) - httprl_variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT));
}
// Adjust Global Timeout if timeout is large and global_timeout is default.
if ($options['timeout'] > httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) && $options['global_timeout'] == httprl_variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT)) {
$options['global_timeout'] = $options['timeout'] + max(1, httprl_variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT) - httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT));
}
// Merge the default headers.
// Set user agent to drupal.
// Set connection to closed to prevent keep-alive from causing a timeout.
$options['headers'] += array(
'User-Agent' => 'Drupal (+http://drupal.org/)',
'Connection' => 'close',
);
// Defaults for url encoding the url.
// Use %20 for spaces in the path and in the query string.
$options['url_encoding'] += array(
'space' => array(),
);
$options['url_encoding']['space'] += array(
'path' => '%20',
'query' => '%20',
);
// Set referrer to current page.
if (!isset($options['headers']['Referer']) && !empty($options['referrer'])) {
if (function_exists('request_uri')) {
$options['headers']['Referer'] = $base_root . request_uri();
}
}
// stream_socket_client() requires timeout to be a float.
$options['timeout'] = (double) $options['timeout'];
}