Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.671
diff -u -p -r1.671 common.inc
--- includes/common.inc	3 Jul 2007 20:16:11 -0000	1.671
+++ includes/common.inc	3 Jul 2007 22:35:21 -0000
@@ -392,11 +392,14 @@ function drupal_access_denied() {
  * @param $retry
  *   An integer representing how many times to retry the request in case of a
  *   redirect.
+ * @param $timeout
+ *   An integer representing how long to wait for the socket to connect,
+ *   and also how long to wait when writing data to the stream.
  * @return
  *   An object containing the HTTP request headers, response code, headers,
  *   data, and redirect status.
  */
-function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
+function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3, $timeout = 15) {
   $result = new stdClass();
 
   // Parse the URL, and make sure we can handle the schema.
@@ -406,13 +409,13 @@ function drupal_http_request($url, $head
     case 'http':
       $port = isset($uri['port']) ? $uri['port'] : 80;
       $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
-      $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
+      $fp = @fsockopen($uri['host'], $port, $errno, $errstr, $timeout);
       break;
     case 'https':
       // Note: Only works for PHP 4.3 compiled with OpenSSL.
       $port = isset($uri['port']) ? $uri['port'] : 443;
       $host = $uri['host'] . ($port != 443 ? ':'. $port : '');
-      $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
+      $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, $timeout);
       break;
     default:
       $result->error = 'invalid schema '. $uri['scheme'];
@@ -456,6 +459,9 @@ function drupal_http_request($url, $head
   }
   $result->request = $request;
 
+  // Set a timeout on the stream
+  stream_set_timeout($fp, $timeout);
+
   fwrite($fp, $request);
 
   // Fetch response.
