Index: wp-cache-phase2.php
===================================================================
--- wp-cache-phase2.php	(revision 7179)
+++ wp-cache-phase2.php	(working copy)
@@ -36,9 +36,24 @@
 		return;
 	if (wp_cache_user_agent_is_rejected()) return;
 	ob_start('wp_cache_ob_callback'); 
-	register_shutdown_function('wp_cache_ob_end');
+	register_shutdown_function('wp_cache_shutdown_callback');
 }
 
+function wp_cache_get_response_headers() {
+	if(function_exists('apache_response_headers')) {
+		$headers = apache_response_headers();
+	} else if(function_exists('headers_list')) {
+		$headers = array();
+		foreach(headers_list() as $hdr) {
+			list($header_name, $header_value) = explode(': ', $hdr, 2);
+			$headers[$header_name] = $header_value;
+		}
+	} else
+		$headers = null;
+
+	return $headers;
+}
+
 function wp_cache_is_rejected($uri) {
 	global $cache_rejected_uri;
 
@@ -110,10 +125,6 @@
 		return $buffer;
 	}
 
-	$meta_object = new CacheMeta;
-	$meta_object->uri = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacs
-	$meta_object->blog_id=$blog_id;
-	$meta_object->post = wp_cache_post_id();
 	$duration = wp_cache_microtime_diff($wp_start_time, microtime());
 	$duration = sprintf("%0.3f", $duration);
 	$buffer .= "\n<!-- Dynamic Page Served (once) in $duration seconds -->\n";
@@ -183,40 +194,43 @@
 	wp_cache_writers_exit();
 }
 
-function wp_cache_ob_end() {
+function wp_cache_shutdown_callback() {
 	global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache;
 	global $meta_object, $known_headers;
 
-	/* Preparing... with PHP5 is straightforward, use headers_list() */
-	if(function_exists('apache_response_headers') ) {
-		$response = apache_response_headers();
-		$meta_object->headers = array();
-		foreach ($known_headers as $key) {
-			if(isset($response{$key})) {
-				array_push($meta_object->headers, "$key: " . $response{$key});
-			}
+	$meta_object = new CacheMeta;
+	$meta_object->uri = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacs
+	$meta_object->blog_id=$blog_id;
+	$meta_object->post = wp_cache_post_id();
+
+	$response = wp_cache_get_response_headers();
+	$meta_object->headers = array();
+	foreach ($known_headers as $key) {
+		if(isset($response{$key})) {
+			array_push($meta_object->headers, "$key: " . $response{$key});
 		}
-		/* Not use because it gives problems with some
-		 * PHP installations
-		if (!$response{'Content-Length'}) {
-		// WP does not set content size
-			$content_size = ob_get_length();
-			@header("Content-Length: $content_size");
-			array_push($meta_object->headers, "Content-Length: $content_size");
-		}
-		*/
-		if (!$response{'Last-Modified'}) {
-			$value = gmdate('D, d M Y H:i:s') . ' GMT';
-			/* Dont send this the first time */
-			/* @header('Last-Modified: ' . $value); */
-			array_push($meta_object->headers, "Last-Modified: $value");
-		}
-		if (!$response{'Content-Type'}) {
-			$value =  "text/html; charset=\"" . get_settings('blog_charset')  . "\"";
-			@header("Content-Type: $value");
-			array_push($meta_object->headers, "Content-Type: $value");
-		}
 	}
+	/* Not use because it gives problems with some
+	 * PHP installations
+	if (!$response{'Content-Length'}) {
+	// WP does not set content size
+		$content_size = ob_get_length();
+		@header("Content-Length: $content_size");
+		array_push($meta_object->headers, "Content-Length: $content_size");
+	}
+	*/
+	if (!$response{'Last-Modified'}) {
+		$value = gmdate('D, d M Y H:i:s') . ' GMT';
+		/* Dont send this the first time */
+		/* @header('Last-Modified: ' . $value); */
+		array_push($meta_object->headers, "Last-Modified: $value");
+	}
+	if (!$response{'Content-Type'}) {
+		$value =  "text/html; charset=\"" . get_settings('blog_charset')  . "\"";
+		@header("Content-Type: $value");
+		array_push($meta_object->headers, "Content-Type: $value");
+	}
+
 	ob_end_clean();
 	if ($new_cache) {
 		$serial = serialize($meta_object);

