? boost-585330.patch
? boost-585424.patch
Index: boost.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v
retrieving revision 1.1.2.1.2.3.2.72
diff -u -p -r1.1.2.1.2.3.2.72 boost.admin.inc
--- boost.admin.inc	19 Sep 2009 02:57:08 -0000	1.1.2.1.2.3.2.72
+++ boost.admin.inc	24 Sep 2009 10:09:40 -0000
@@ -227,6 +227,12 @@ function boost_admin_boost_performance_p
     '#default_value' => BOOST_ONLY_ASCII_PATH,
     '#description'   => t('Only allowing ACSII characters is a safe way to cache pages. It severely limits i18n support so this can be turned off. Fair warning, disabling this may cause "page not found" errors depending on your url structure (spaces are bad, ect...). If you follow RFC 3986 you should be ok.'),
   );
+  $form['advanced']['boost_asynchronous_output'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Asynchronous Opperation: output HTML, close connection, then store static file.'),
+    '#default_value' => BOOST_ASYNCHRONOUS_OUTPUT,
+    '#description'   => t('Run php in the background. When a cached page is generated, this will allow for faster page generation; downside is the headers are not the standard ones outputted by drupal; sends "Connection: close" instead of "Connection: Keep-Alive".'),
+  );
   $form['advanced']['boost_flush_dir'] = array(
     '#type'          => 'checkbox',
     '#title'         => t('Clear all empty folders from cache.'),
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.144
diff -u -p -r1.3.2.2.2.5.2.144 boost.module
--- boost.module	19 Sep 2009 02:16:32 -0000	1.3.2.2.2.5.2.144
+++ boost.module	24 Sep 2009 10:09:41 -0000
@@ -48,6 +48,7 @@ define('BOOST_FETCH_METHOD',         var
 define('BOOST_PRE_PROCESS_FUNCTION', variable_get('boost_pre_process_function', ''));
 define('BOOST_POST_UPDATE_COMMAND',  variable_get('boost_post_update_command', ''));
 define('BOOST_CRON_LIMIT',           variable_get('boost_cron_limit', 100));
+define('BOOST_ASYNCHRONOUS_OUTPUT',  variable_get('boost_asynchronous_output', TRUE));
 define('BOOST_ONLY_ASCII_PATH',      variable_get('boost_only_ascii_path', TRUE));
 define('BOOST_GZIP',                 variable_get('page_compression', TRUE));
 define('BOOST_AGGRESSIVE_GZIP',      variable_get('boost_aggressive_gzip', FALSE));
@@ -164,7 +165,8 @@ function boost_init() {
       $GLOBALS['conf']['cache'] = CACHE_DISABLED;
     }
     $GLOBALS['_boost_cache_this'] = TRUE;
-    ob_start('_boost_ob_handler');
+    register_shutdown_function('_boost_ob_handler');
+    ob_start();
   }
 }
 
@@ -798,13 +800,10 @@ function theme_boost_cache_status($ttl, 
 
 /**
  * PHP output buffering callback for static page caching.
- *
- * NOTE: objects have already been destructed so $user is not available.
- *
- * @param $buffer
- *   Pages contents
  */
-function _boost_ob_handler($buffer) {
+function _boost_ob_handler() {
+  $buffer = ob_get_contents();
+
   // Ensure we're in the correct working directory, since some web servers (e.g. Apache) mess this up here.
   chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 
@@ -820,7 +819,8 @@ function _boost_ob_handler($buffer) {
         if (BOOST_VERBOSE >= 3) {
           watchdog('boost', 'There are <strong>php errors</strong> on this page, preventing boost from caching. ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => boost_print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
         }
-        return $buffer;
+        echo $buffer;
+        return FALSE;
       }
     }
   }
@@ -828,7 +828,8 @@ function _boost_ob_handler($buffer) {
     if (BOOST_VERBOSE >= 3) {
       watchdog('boost', 'There are <strong>drupal messages</strong> on this page, preventing boost from caching. MESSAGES: %msg <br /> !performance', array('%msg' => $GLOBALS['_boost_message_count'], '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
     }
-    return $buffer;
+    echo $buffer;
+    return FALSE;
   }
 
 
@@ -836,11 +837,19 @@ function _boost_ob_handler($buffer) {
   // going to be exceedingly conservative here and only cache 'text' pages that
   // were output with a 200 OK status. If it didn't get a 200 then remove that
   // entry from the cache.
+  $output_needed = TRUE;
   if ($GLOBALS['_boost_cache_this'] && strlen($buffer) > 0) {
     switch (_boost_get_content_type()) {
       case 'text/html':
         if (_boost_get_http_status() == 200) {
-          boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_FILE_EXTENSION);
+          // Output page, and kill connection; do background processing.
+          if (BOOST_ASYNCHRONOUS_OUTPUT) {
+            boost_async_opp($buffer, FALSE, 'text/html');
+            $output_needed = FALSE;
+          }
+          if (BOOST_CACHE_HTML) {
+            boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_FILE_EXTENSION);
+          }
           boost_cache_css_js_files($buffer);
         }
         else {
@@ -856,7 +865,14 @@ function _boost_ob_handler($buffer) {
       case 'text/xml':
       case 'application/rss+xml':
         if (_boost_get_http_status() == 200) {
-          boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_XML_EXTENSION);
+          // Output page, and kill connection; do background processing.
+          if (BOOST_ASYNCHRONOUS_OUTPUT) {
+            boost_async_opp($buffer, FALSE, 'text/xml');
+            $output_needed = FALSE;
+          }
+          if (BOOST_CACHE_XML) {
+            boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_XML_EXTENSION);
+          }
         }
         else {
 //           boost_cache_expire_derivative($path);
@@ -869,7 +885,14 @@ function _boost_ob_handler($buffer) {
         break;
       case 'text/javascript':
         if (_boost_get_http_status() == 200) {
-          boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_JSON_EXTENSION);
+          // Output page, and kill connection; do background processing.
+          if (BOOST_ASYNCHRONOUS_OUTPUT) {
+            boost_async_opp($buffer, FALSE, 'text/javascript');
+            $output_needed = FALSE;
+          }
+          if (BOOST_CACHE_JSON) {
+            boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_JSON_EXTENSION);
+          }
         }
         else {
 //           boost_cache_expire_derivative($path);
@@ -882,9 +905,9 @@ function _boost_ob_handler($buffer) {
         break;
     }
   }
-
-  // Allow the page request to finish up normally
-  return $buffer;
+  if ($output_needed) {
+    echo $buffer;
+  }
 }
 
 /**
@@ -1228,25 +1251,16 @@ function boost_cache_set($path, $data = 
   // Code commenting style based on what is being cached.
   switch ($extension) {
     case BOOST_FILE_EXTENSION:
-      if (!BOOST_CACHE_HTML) {
-        return FALSE;
-      }
       $comment_start = '<!-- ';
       $comment_end = " -->\n";
       $expire = BOOST_CACHE_LIFETIME;
       break;
     case BOOST_XML_EXTENSION:
-      if (!BOOST_CACHE_XML) {
-        return FALSE;
-      }
       $comment_start = '<!-- ';
       $comment_end = " -->\n";
       $expire = BOOST_CACHE_XML_LIFETIME;
       break;
     case BOOST_JSON_EXTENSION:
-      if (!BOOST_CACHE_JSON) {
-        return FALSE;
-      }
       $comment_start = '/* ';
       $comment_end = " */\n";
       $expire = BOOST_CACHE_JSON_LIFETIME;
@@ -1270,6 +1284,12 @@ function boost_cache_set($path, $data = 
   }
   db_set_active();
 
+  // Final check, make sure this page should be cached. Allow for the preprocess
+  // function to have a final say in if this page should be cached.
+  if (!$GLOBALS['_boost_cache_this']) {
+    return FALSE;
+  }
+
   // Create or update the static files as needed
   if (($filename = boost_file_path($path, TRUE, $extension)) && (BOOST_OVERWRITE_FILE || !file_exists($filename) || boost_db_is_expired($filename))) {
     // Special handling of the front page for aggressive gzip test
@@ -2522,8 +2542,17 @@ function boost_crawler_run() {
 
 /**
  * Output text & set php in async mode.
+ *
+ * @param $output
+ *  string - Text to output to open connection.
+ * @param $wait
+ *  bool - Wait 1 second?
+ * @param $content_type
+ *  string - Content type header.
+ * @param $length
+ *  int - content lenght
  */
-function boost_async_opp($output) {
+function boost_async_opp($output, $wait = TRUE, $content_type = "text/html") {
   // Prime php for background operations
   while (ob_get_level()) {
     ob_end_clean();
@@ -2533,17 +2562,29 @@ function boost_async_opp($output) {
 
   // Output text
   ob_start();
-  header("Content-type: text/html");
-  header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
+  header("Content-type: " . $content_type);
+  header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
   header("Cache-Control: no-cache");
   header("Cache-Control: must-revalidate");
-  header("Content-Length: " . (strlen($output)-1));
+  if ($content_type == 'image/gif') {
+    header("Content-Length: 43");
+  }
+  else {
+    header("Content-Length: " . (strlen($output)-1));
+  }
   header("Connection: close");
-  print($output);
+  if ($content_type == 'image/gif') {
+    printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
+  }
+  else {
+    print($output);
+  }
   ob_end_flush();
   flush();
   // wait for 1 second
-  sleep(1);
+  if ($wait) {
+    sleep(1);
+  }
 
   // text returned and connection closed.
   // Do background processing. Time taken after should not effect page load times.
Index: stats/boost_stats.ajax.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/stats/Attic/boost_stats.ajax.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 boost_stats.ajax.inc
--- stats/boost_stats.ajax.inc	12 Sep 2009 23:03:58 -0000	1.1.2.4
+++ stats/boost_stats.ajax.inc	24 Sep 2009 10:09:41 -0000
@@ -7,7 +7,7 @@
 function boost_stats_ajax_callback() {
   if (!isset($_GET['js'])) {
     // stats not called via JS, send image out & close connection.
-    boost_stats_async_image();
+    boost_async_opp('1px image', TRUE, 'image/gif');
   }
 
   // Exit if nothing was passed to this.
@@ -121,31 +121,3 @@ function boost_stats_output_stats_block(
 
   return array('#boost-stats' => $block);
 }
-
-/**
- * Returns a 1px image and allows for php to run in the background.
- */
-function boost_stats_async_image() {
-  // Script should take under 1MB of memory to work.
-  // Prime php for background operations
-  while (ob_get_level()) {
-    ob_end_clean();
-  }
-  header("Connection: close");
-  ignore_user_abort();
-
-  // Output of 1 pixel transparent gif
-  ob_start();
-  header("Content-type: image/gif");
-  header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
-  header("Cache-Control: no-cache");
-  header("Cache-Control: must-revalidate");
-  header("Content-Length: 43");
-  header("Connection: close");
-  printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
-  ob_end_flush();
-  flush();
-
-  // Image returned and connection closed.
-  // Do background processing. Time taken after this should not effect page loading.
-}
\ No newline at end of file
