XAJAX Comet Plugin

vers 0.2.2

about this plugin

This plugin allows to stream xajax response commands to the client using so called "comet streaming". While the streaming process is running you can still fire any other XHRs in the background.

The zip file contains the latest xajax 0.5 SVN version, the preinstalled comet plugin as well as an example file.

download version 0.2.2

Since the IE doesn't support multipart XHRs I had to create a fallback method using a hidden iframe (no polling!). Avoid streaming large amounts of data or LONG (I mean hours) time streaming, since it will increase the memory usage in IE.

I wrote an experimental IRC chat using this plugin to test the functionality and it worked fine (even for hours), but you have to keep an eye on your script's memory usage. Imagine you have 100 users using your application at the same time and each process uses 10MB of RAM. 100x10MB = 1000MB RAM!

This plugin is not meant to replace any socket server solution that is running all the time in background. It fills the gap between common asynchronous XHRs and 'high-end' socket based solutions in the simplified xajax way.

To reduce the load on the webserver as well as the server-client traffic this plugin triggers a sleep timeout right after flushing the response queue. The sleep timeout raises the chances for other processes on the server to get some more cpu cycles from the kernel. ;)
The setup is quite easy and should be self explanatory when you look into the comet.php file. If you still have any questions or stuck getting it to work, join the xajax community forums.

install / syntax

1. Copy this plugin todo xajax/xajax_plugins/response/

2. Include the plugin right after including the xajax core and before calling ->configure();
$xajax = new xajax();
require_once $core . '/xajaxPlugin.inc.php';
require_once $core . '/xajaxPluginManager.inc.php';
require_once './xajax/xajax_plugins/response/comet/comet.inc.php';
	
3. register your comet function
$xajax->register(XAJAX_FUNCTION,"testComet",array("comet" => true));
4. inside your functions use xajaxCometResponse instead of xajaxResponse.
Call ->flush() to flush the commands from the response queue.
function testComet () {
  $objResponse = new xajaxCometResponse(0.3);

  for ($i=1;$i<=10;++$i) {
    $objResponse->assign("progress","style.width",($i*5)."px");
    $objResponse->assign("streaming","innerHTML",($i*5).'%
'); $objResponse->flush(); } $objResponse->assign("progress","style.width",($i*5)."px"); $objResponse->assign("streaming","innerHTML",($i*5).'%
'); $objResponse->alert("finished process at ".($i*5)."%."); return $objResponse; }

Thanks for using this plugin.

Donations keep developers happy :)

changelog

2008-10-25 vers 0.2.2 2008-7-18 vers 0.2.1 2008-05-26 vers 0.2 2008-05-26 vers 0.1

supported configurations:

supported browsers:

demo