diff --git a/httprl.module b/httprl.module index 379f453..f1f3a26 100644 --- a/httprl.module +++ b/httprl.module @@ -1229,9 +1229,22 @@ function httprl_send_request($results = NULL) { $except = array(); // Do some voodoo and open all streams at once. Wait 25ms for streams to // respond. - $n = stream_select($read, $write, $except, $stream_select_timeout, 25000); + $n = @stream_select($read, $write, $except, $stream_select_timeout, 25000); $stream_select_timeout = 0; + // An error occured with the streams. Remove bad ones. + if ($n === FALSE) { + $merged = array_unique(array_merge($read, $write, $except)); + foreach ($merged as $m) { + $id = array_search($m, $this_run); + @fclose($m); + if ($id !== FALSE && isset($responses[$id])) { + watchdog('httprl', 'The following url had a stream_select error and had to be terminated: %info', array('%info' => $responses[$id]->url), WATCHDOG_ERROR); + unset($responses[$id]); + } + } + } + // We have some streams to read/write to. $rw_done = FALSE; if (!empty($n)) { @@ -1711,6 +1724,12 @@ function httprl_post_processing($id, &$responses, &$output, $time_left = NULL) { // 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(). @@ -1732,16 +1751,11 @@ function httprl_post_processing($id, &$responses, &$output, $time_left = NULL) { httprl_queue_background_callback($result->options['background_callback'], $result); } - // 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); - } - // Copy the result to the output array. if (isset($result->url)) { $output[$result->url] = $result; } - unset($responses[$id]); + } /**