From 36b8d5b1768714540152fc3709c5d6ba9ebe0003 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Fri, 27 May 2011 22:15:35 -0400
Subject: [PATCH] Issue #1055276 by pillarsdotnet: Add configurable chunksize to drupal_http_request().

---
 includes/common.inc                |    4 +++-
 sites/default/default.settings.php |   10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index 95e03e8cc93e6d41ee5780e9019bd9e50607f547..26d07af000c5be501e84c0032219b3bd8370aec2 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -742,6 +742,7 @@ function drupal_access_denied() {
  *     call may take. The default is 30 seconds. If a timeout occurs, the error
  *     code is set to the HTTP_REQUEST_TIMEOUT constant.
  *   - context: A context resource created with stream_context_create().
+ *   - buffer: The maximum number of bytes read between end-of-file checks.
  *
  * @return object
  *   An object that can have one or more of the following components:
@@ -788,6 +789,7 @@ function drupal_http_request($url, array $options = array()) {
     'max_redirects' => 3,
     'timeout' => 30.0,
     'context' => NULL,
+    'buffer' => variable_get('http_request_buffer',1024),
   );
   // stream_socket_client() requires timeout to be a float.
   $options['timeout'] = (float) $options['timeout'];
@@ -902,7 +904,7 @@ function drupal_http_request($url, array $options = array()) {
       break;
     }
     stream_set_timeout($fp, floor($timeout), floor(1000000 * fmod($timeout, 1)));
-    $chunk = fread($fp, 1024);
+    $chunk = fread($fp, $options['buffer']);
     $response .= $chunk;
     $info = stream_get_meta_data($fp);
     $alive = !$info['eof'] && !$info['timed_out'] && $chunk;
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 0472f02b1c3bdf1344cf9ddad90e302d799083c4..013301cc4da563f6d75284e6c98c192ccf1826b6 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -391,6 +391,16 @@ ini_set('session.cookie_lifetime', 2000000);
 # $conf['js_gzip_compression'] = FALSE;
 
 /**
+ * HTTP Request Buffer
+ *
+ * When drupal requests a file from another webserver, it periodically checks
+ * for end-of-file and server timeouts.  The default is to read a maximum of
+ * 1024 bytes between each check.  Increasing this limit may help performance
+ * when reading large files from the network.
+ */
+# $conf['http_request_buffer'] = 1024;
+
+/**
  * String overrides:
  *
  * To override specific strings on your site with or without enabling locale
-- 
1.7.4.1

