Topic: [0.2] Comet Streaming plugin

Good news everyone,

I updated the comet streaming plugin. The Comet plugin is now fully compatible with latest SVN rev. I fixed some small issues reported by dabreaka.

Please let me know if you experience any issues.



demo


download
xajax.ext.comet-0.2.zip

demo source

<?
ini_set("display_errors",1);
error_reporting(E_ALL ^E_NOTICE);

$core = './xajax/xajax_core';
require_once $core . '/xajax.inc.php';

$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';
 
$xajax->configure("javascript URI","/swfupload/xajax/");


$xajax->register(XAJAX_FUNCTION,"testComet",array("comet" => true));
$xajax->register(XAJAX_FUNCTION,"testNormal");

$xajax->processRequest();

function testComet () {
    $objResponse = new xajaxCometResponse(0.2);

    for ($i=0;$i<=5    ;++$i) {
        $objResponse->assign("progress","style.width",($i*3)."px");
        $objResponse->assign("progress","innerHTML",($i*2).'%');
        $objResponse->flush();
    }
$objResponse->alert("done");
    
    return $objResponse;
}

function testNormal() {
    $objResponse = new xajaxResponse();
    $objResponse->append("streaming","innerHTML","normal XHR <br />");
    $objResponse->alert("foo");
    return $objResponse;
}




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>XAJAX Comet Plugin</title>
<?php $xajax->printJavaScript();?>
<link rel="stylesheet" type="text/css" href="demo.css" />
</head>
<body>

    <h1>XAJAX Comet Plugin</h1>
    <div id="docs" style="float:left;width:500px;">
    
    <h2>vers 0.2</h2>
    <h3>changelog</h2>
    2008-05-26 vers 0.2
    <ul>
        <li>minified JS</li>
        <li>fixed bug were response commands added after ->flush() werent sent</li>
        <li>improved XHR streaming</li>
        <li>added optional parameter to adjust the sleepTimeout</li>
    </ul>
    2008-05-26 vers 0.1
    <ul>
        <li>initial release</li>
    </ul>
        <p>
            <h3>supported configurations:</h3>
            <ul>
                <li>any webserver</li>
                <li>PHP 5.x</li>
            </ul>
            <h3>supported browsers:</h3>
            <ul>
                <li>Firefox 2/3</li>
                <li>IE 6/7 </li>
                <li>Opera 9</li>
                <li>Safari 3</li>
            </ul>        
        </p>
    </div>
    <div id="example">
        <h2>demo</h2>
        <input type="button" onclick="xajax_testComet();" value="start comet" />
        <input type="button" onclick="xajax_testNormal();" value="start normal request" />
        <div id="progress" style="width:1px;background:red;border:1x solid darkred"></div>
        <div id="streaming"></div>
        
    </div>
<br style="clear:both;" />

<div id="copyright">
Copyright (c) 2007-2008 by Steffen Konerow <br />
</div>

2 (edited by halski103 2008-05-26 11:20:48 PM)

Re: [0.2] Comet Streaming plugin

hi

DEMO

Only 10% and alert done sad

here is firebug:

<xjx><cmd cmd="as" id="progress" prop="style.width">S0px</cmd><cmd cmd="as" id="progress" prop="innerHTML"

>S0%</cmd></xjx><xjx><cmd cmd="as" id="progress" prop="style.width">S3px</cmd><cmd cmd="as" id="progress"

prop="innerHTML">S2%</cmd></xjx><xjx><cmd cmd="as" id="progress" prop="style.width">S6px</cmd><cmd cmd

="as" id="progress" prop="innerHTML">S4%</cmd></xjx><xjx><cmd cmd="as" id="progress" prop="style.width"

>S9px</cmd><cmd cmd="as" id="progress" prop="innerHTML">S6%</cmd></xjx><xjx><cmd cmd="as" id="progress"

prop="style.width">S12px</cmd><cmd cmd="as" id="progress" prop="innerHTML">S8%</cmd></xjx><xjx><cmd

cmd="as" id="progress" prop="style.width">S15px</cmd><cmd cmd="as" id="progress" prop="innerHTML">S10

%</cmd></xjx><xjx><cmd cmd="al">Sdone</cmd></xjx>

P.S.

What meen "S" Sdone, S10% .....

Is this added by firebug ?

Re: [0.2] Comet Streaming plugin

it's not intended to get beyond 10% as you can see in the source code smile
great job q_no, as always smile

Re: [0.2] Comet Streaming plugin

i can see the loop now wink

Re: [0.2] Comet Streaming plugin

halski, the latest SVN rev of xajax takes care of the argument types. So strings will be passed as strings and NULL as NULL (what resulted in 0 or empty strings before). That's why it adds additional chars to the responses.
The demo is supposed to display 10% only. I was bored of watching it incrementing to 100 during the tests. wink

Re: [0.2] Comet Streaming plugin

Maybe my net is too quick. hihi
The progress bar is immediately 10% after click the button wink

Thx for explanation "S"

Re: [0.2] Comet Streaming plugin

halski, the plugin uses a sleeptimout to slow down the reponses. Long running processes can stress a server to death - the sleep timeout raises the chances for other processes to get some free cpu cycles from the kernel wink

The default value is 1sec, but you can override it using:

$objResponse = new xajaxCometResponse(0.2);

try to change that value and tell me what happens

Re: [0.2] Comet Streaming plugin

hi

Its, oki now.

Vale from 0.1 to ... works fine.
Maybe my comp was too overloaded and FF refresh time was too slow.
That time i have other processes running in background.

Re: [0.2] Comet Streaming plugin

I thought xajax auto loads plugins for you as long as you upload the files?  Just curious.

10 (edited by atDev 2008-06-05 6:20:26 PM)

Re: [0.2] Comet Streaming plugin

Couldn't get this to work its probably conflicting with something.  Does it work with the loading messages options?  When running it brings up my standard loading message I use globally, but after that nothing happens.

Re: [0.2] Comet Streaming plugin

My Comet no longer functions with IIS7. Has anyone got their Comet to work on IIS7???

Re: [0.2] Comet Streaming plugin

Hmm.. do you receive any error messages? Have you tried reinstalling xajax? Please make sure that you'r using the svn rev provided with the comet zip file

13 (edited by davidmoller 2008-06-10 11:31:48 PM)

Re: [0.2] Comet Streaming plugin

q_no wrote:

Hmm.. do you receive any error messages? Have you tried reinstalling xajax? Please make sure that you'r using the svn rev provided with the comet zip file

I am using the latest...which worked great in IIS6, but I had to replace my server and I figured I would play with Windows 2008 / IIS7. No errors, just no "streaming" content. Using the comet test, the %complete bar does not update, just pops in after a few seconds (no counting up as it should).

Take a peek if you wish:

http://www.interlink2k.com/myGeocode/comet.php

I only changed the math a little for testing purposes.

function testComet () {
    $objResponse = new xajaxCometResponse(0.2);

    for ($i=0;$i<=10    ;++$i) {
        $objResponse->assign("progress","style.width",($i*10)."px");
        $objResponse->assign("progress","innerHTML",($i*10).'%');
        $objResponse->flush();
    }
$objResponse->alert("done");
   
    return $objResponse;
}

Re: [0.2] Comet Streaming plugin

Try to check your webserver and PHP settings if there's output buffering enabled somewhere.

Re: [0.2] Comet Streaming plugin

PHP's output_buffering is commented out and I did disable IIS7 buffering for this domain (already done before I posted the original message). I am trying to poke around in IIS7 to see what else I can find.

Re: [0.2] Comet Streaming plugin

Hi,

I searched for a comet lamp solution quite a while and never find something great.
Finally, it seems that a comet like system using LAMP was a bad solution... and now you provide a solution !

I didnt try yet  your plugin but I get few question :
- Normally, comet style leave a port open during the whole process, is it the case ? (it seem with some flush php call)
   - So, if yes how do you handle timeout from server or client ? doest it run for XX seconds and the make a new call to start a fresh new comet process ?

- In Lamp architecture, each process is a thread with an instance of apache and php. So each process is mem consuming. So, is your system is quite scalable ? or we cant use it on production site with many visitors ?

- Perhaps, I miss something, but can it use handler ? like defining some event on the php side to update the comet process ?

Best regards

Re: [0.2] Comet Streaming plugin

Hi,

the comet plugin doesn't reconnect when a stream fails or times out atm. It's more a basic streaming implementation for tasks that do not run longer than a few min. I made some tests in an IRC application and it worked fine even for hours, but I cannot guarantee that it won't fail after a certain amount of time.

This plugin just creates a kinda infinite loop on the server and returns a response once per flush. After flushing the response queue it triggers a sleep (default is 1sec) to raise the chances for other processes to get some more CPU cycles from the kernel. Furthermore, PHPs max_execution_time counts only the cpu time - not the sleep. So this way you can gain some extra time before the script reaches the max_exec limit and keep the cpu usage low.

There's one thing you have to keep in mind when using this plugin:
Watch your RAM usage! Keep the comet script as small as possible for a better scalability!

Imagine you have a comet function that runs for 5min and takes 20MB RAM. 10 users in parallel would take 200MB RAM!

I hope I could clarify some of your questions... if you'r still not sure if it fits your needs, just give a shot and let me know what you think about it smile Don't hesitate to ask more questions smile

Re: [0.2] Comet Streaming plugin

Hi,

Thanks for your answer, it about what I'm thinking.

Do your think its simple to implement some basic stop and reload for comet stream ?
Can we imagine that every 5 minutes, the comet stream stop, and restary for a new fresh stream ?

Another thing, is the server has the capabilities to detect that a client has close his browser ?

Best regards

Re: [0.2] Comet Streaming plugin

Hi,

After some long searches about comet, I found one nice project : http://meteorserver.org/

It work like a 'proxy' between a live event application and clients on browser to send realtime data.

Do you think its simple to just use the 'rendering part' of xajax (to change thing on DOMelement) using a third party project like this ?

Its just a question, and I dont want to shock you about your work. I think its impressive, but to serve large number of clients over a long period, its not best way (because of apache, ...)

Regards

20 (edited by hali2k 2008-07-03 7:22:10 AM)

Re: [0.2] Comet Streaming plugin

hi,
thank to q_no sir for this plugin.

but I had a problem ,when I'm use this plugin ,I find I can't use xajaxComet.getFormValues with it together..
like it :
html:
<input name="a" type="text" id="a" onBlur="xajax_showprogress(xajax.getFormValues('form1'));" >
code:
function showprogress($data)
{
extract($data);   
$show_progress_where=$$data;
$objResponse = new xajaxCometResponse(0.2);
for ($i=0;$i<=25;$i++)
{
$objResponse->assign($show_progress_where,"style.width",($i*2)."px");               
$objResponse->flush();
}
return $objResponse; 
}


what's wrong I did?

Best regards

Re: [0.2] Comet Streaming plugin

hali2k wrote:

hi,
thank to q_no sir for this plugin.

but I had a problem ,when I'm use this plugin ,I find I can't use xajaxComet.getFormValues with it together..
like it :
html:
<input name="a" type="text" id="a" onBlur="xajax_showprogress(xajax.getFormValues('form1'));" >
code:
function showprogress($data)
{
extract($data);   
$show_progress_where=$$data;
$objResponse = new xajaxCometResponse(0.2);
for ($i=0;$i<=25;$i++)
{
$objResponse->assign($show_progress_where,"style.width",($i*2)."px");               
$objResponse->flush();
}
return $objResponse; 
}


what's wrong I did?

Best regards

xajax.getFormvalues() should work fine. the comet plugin just uses a different way for the transport, but all passed data remain the same, no matter if it's a comet function or not.

This line looks a bit odd

$show_progress_where=$$data;

Re: [0.2] Comet Streaming plugin

hi everyone!

Does any one know why I cannot get comet plugin working?. I have tried to run this demo: 
http://xajaxproject.org/developer/q_no/ … et-0.2.zip but only the normal request works. I have also tried downloading the latest comet version (0.2.2) and xajax 0.5 (final) but nothing...it still doesn't work. It shows
"ERROR: No response processor is available to process the response from the server.Content-Type: text/html.Check for error messages from the server." when using xajaxCometResponse

Re: [0.2] Comet Streaming plugin

hello,

i try the comet plugin, in firefox it works very well.

in ie my debugger cause problem ... so i looked at the code and see that an iframe is create when the browser is ie.

and i saw that de document domain is hard codded !!!
comet.js :

try
    {
        xjxEc.transferDoc = new ActiveXObject("htmlfile");
        xjxEc.transferDoc.open();
        xjxEc.transferDoc.write("<html>");
        xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");
        xjxEc.transferDoc.write("</html>");
        xjxEc.transferDoc.close();
        xjxEc.ifrDiv = xjxEc.transferDoc.createElement("div");
        xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);
        xjxEc.ifrDiv.innerHTML = "<iframe src='" + url + "'></iframe>";
        xjxEc.transferDoc.callback = function (response)
        {
            callback(response, oRequest);
        };
    }

so that's pretty anoying
(sorry for my poor english)

Re: [0.2] Comet Streaming plugin

i resolve my problem by deleting the line :

 
xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");

ie : i don't set the domain.
it's work well with ie7 and firefox3

Re: [0.2] Comet Streaming plugin

Oh, I'm sorry...looks like there's still debugcode inside the plugin :-|