function httprl_post_processing in HTTP Parallel Request & Threading Library 7
Same name and namespace in other branches
- 6 httprl.module \httprl_post_processing()
Run post processing on the request if we are done reading.
Decode transfer-encoding and content-encoding. Reconstruct the internal redirect arrays.
@result object An object from httprl_send_request.
1 call to httprl_post_processing()
- httprl_send_request in ./
httprl.module - Perform many HTTP requests.
File
- ./
httprl.module, line 2073 - HTTP Parallel Request Library module.
Code
function httprl_post_processing($id, &$responses, &$output, $time_left = NULL) {
// Create the result reference.
$result =& $responses[$id];
// Close file.
if (isset($result->fp)) {
if (empty($responses[$id]->options['blocking'])) {
$ms_delay = httprl_variable_get('httprl_non_blocking_fclose_delay', HTTPRL_NON_BLOCKING_FCLOSE_DELAY);
if (!empty($ms_delay)) {
// Wait X ms before closing a non blocking connection.
usleep($ms_delay * 1000);
}
}
@fclose($result->fp);
unset($result->fp);
}
// Set timeout.
if (is_null($time_left)) {
$time_left = $result->options['timeout'] - $result->running_time;
}
$result->options['timeout'] = $time_left;
// Assemble redirects.
httprl_reconstruct_redirects($result);
// Decode chunked transfer-encoding and gzip/deflate content-encoding.
httprl_decode_data($result);
// If this is a background callback request, extract the data and return.
if (isset($result->options['internal_states']) && array_key_exists('background_function_return', $result->options['internal_states']) && isset($result->headers['content-type']) && strpos($result->headers['content-type'], 'application/x-www-form-urlencoded') !== FALSE) {
httprl_extract_background_callback_data($result);
unset($responses[$id]);
return;
}
// See if a full bootstrap has been done.
$full_bootstrap = httprl_drupal_full_bootstrap();
// Allow a user defined function to alter all $responses.
if ($full_bootstrap && !empty($result->options['alter_all_streams_function']) && function_exists($result->options['alter_all_streams_function'])) {
$result->options['alter_all_streams_function']($id, $responses);
}
unset($responses[$id]);
// Allow other modules to alter the result.
if ($full_bootstrap) {
// Call hook_httprl_post_processing_alter().
drupal_alter('httprl_post_processing', $result);
}
// Run callback so other modules can do stuff in the event loop.
if ($full_bootstrap && !empty($result->options['callback']) && is_array($result->options['callback']) && !empty($result->options['callback'][0]) && is_array($result->options['callback'][0]) && !empty($result->options['callback'][0]['function'])) {
httprl_run_callback($result);
}
// Run background_callback.
if (!empty($result->options['background_callback']) && is_array($result->options['background_callback']) && !empty($result->options['background_callback'][0]) && is_array($result->options['background_callback'][0]) && !empty($result->options['background_callback'][0]['function'])) {
$call_is_queued = httprl_queue_background_callback($result->options['background_callback'], $result);
if (is_null($call_is_queued)) {
watchdog('httprl', 'Background callback attempted but it is disabled. Going to use a normal callback');
unset($result->options['callback']);
$result->options['callback'] = $result->options['background_callback'];
unset($result->options['background_callback']);
httprl_run_callback($result);
}
}
// Copy the result to the output array.
if (isset($result->url)) {
$output[$result->url] = $result;
}
}