Add Output class for Comet (HTTP incremental streams) -- experimental and not working with every browser/apache configuration.
authorDan Fuhry <dan@enanocms.org>
Mon, 19 Nov 2012 11:38:34 -0500
changeset 1371 d9814c4c2948
parent 1370 24f5610ea589
child 1372 947153b432ea
Add Output class for Comet (HTTP incremental streams) -- experimental and not working with every browser/apache configuration.
includes/output.php
--- a/includes/output.php	Mon Nov 19 11:37:36 2012 -0500
+++ b/includes/output.php	Mon Nov 19 11:38:34 2012 -0500
@@ -273,6 +273,41 @@
 }
 
 /**
+ * Output engine that sends data using Comet. This allows incremental pushing of data.
+ * Note that this tends to not work with every server.
+ */
+
+class Output_Comet extends Output_Naked
+{
+	/**
+	 * Be warned: this header function will flush ALL output buffers!
+	 */
+	
+	public function header()
+	{
+		while ( ob_get_level() )
+			ob_end_flush();
+	}
+	
+	/**
+	 * Write data and immediately send it to the client.
+	 * @param string Data to write
+	 */
+	
+	public function write($data)
+	{
+		echo $data;
+		flush();
+		if ( $data === 'STOP' || !stristr(@$_SERVER['HTTP_USER_AGENT'], 'gecko') || stristr(@$_SERVER['HTTP_USER_AGENT'], 'like gecko') )
+		{
+			global $db;
+			$db->close();
+			exit;
+		}
+	}
+}
+
+/**
  * Safe template outputter
  */