PDA

View Full Version : ExtJS 3.0: Ext.Direct with PHP: Polling:ok and Pushing ?



freygrob
17 Apr 2009, 1:31 PM
Hi From Paris, France,

First, here's a sample of Ext.Direct.PollingProvider use with PHP (from original sample for .NET 3.5 written by shibub) (http://www.extjs.com/forum/showthread.php?t=65691)

direct.js :


Ext.onReady(function() {

var out = new Ext.form.DisplayField({
cls: 'x-form-text',
id: 'out'
});

var panel = new Ext.Panel({
title: 'Remote Call Log',
width: 600,
height: 300,
layout: 'fit',
fitToFrame: true,
autoScroll: true,
items: [out]
});
panel.render(Ext.getBody());

Ext.Direct.addProvider({
type: 'polling',
url: 'poll.php'
});

Ext.Direct.on('message', function(e) {
out.append(String.format('<p>Successfully polled at: {0}</p>', e.data));
out.el.scrollTo('t', 100000, true);
});

});
and php backend (poll.php) :


<?php
$time = date(DATE_ATOM, time());

echo json_encode(array(
"type" => "event",
"name" => "message",
"data" => $time
));
?>
=> ok for polling from Ext.Direct.

But in Ext 3.0 Roadmap, I saw a "Comet support" line.
So, now, how can I "push" from server to client ?
Imagine if php backend was endless and, instead of polling each 3 seconds, pushing its data to client ?
Excuse my english !
I would like my php backend push data to ExtJS Client as this comet sample push data in a <iframe>: http://www.zeitoun.net/articles/comet_and_php/start
and do something like this in php backend :


while(1) {
echo (http://www.php.net/echo) '<script type="text/javascript">';
echo (http://www.php.net/echo) 'comet.printServerTime('.time (http://www.php.net/time)().');';
echo (http://www.php.net/echo) '</script>';
flush (http://www.php.net/flush)(); // used to send the echoed data to the client
sleep (http://www.php.net/sleep)(1); // a little break to unload the server CPU
}
or



while(1) {
echo json_encode(...);
sleep(1); // something to do on the server that takes long time...
}

mjlecomte
17 Apr 2009, 2:11 PM
Do you realize there's already php samples included in the SDK? I did not detect any examples of pushing from the server though, so I'm confused about the alleged comet capability myself (I didn't go to the conference so I missed any conversation about this).

deanna
17 Apr 2009, 2:28 PM
I don't think you would want to do much comet with php. PHP would tie up connections on your http server and cause bad overall performance. My impression of comet is you need something like a java serverlet or some other type of server that can hold open lots of connections.

My read on Ext.direct so far seems to be it is a way to easily import and use remote api's.

evant
17 Apr 2009, 2:32 PM
We will be implementing a LongPollingProvider (Comet) at some point. Stay tuned...

mjlecomte
17 Apr 2009, 2:35 PM
Oh, by the way, I mentioned this to some folks and it kind of died. Perhaps some of y'all will study it and post any insights / findings. Open up the SDK direct example that polls the server with php (maybe this is a php issue as you say?). Anyway, leave it run for 3+ hours and watch the memory AND CPU usage of the browser. I found that the CPU usage really throttled my processor after a time.

freygrob
17 Apr 2009, 2:52 PM
@mjlecomte : I'm sorry I already use direct sample from SDK... to poll... but there is nothing about push...

@evant : Yes ! of course I stay tuned ! ExtJS is really a GOOD JOB !
Thank you ExtJS Team for all your works.

ckr
5 May 2009, 5:01 AM
You might look here (http://extjs.com/forum/showthread.php?p=324039#post324039)

This is not with Ext.Direct, but it does long polling which is what is typically used in a comet push. It is a very simplistic example. More would need to be added for timeouts etc.

jay@moduscreate.com
5 May 2009, 7:16 AM
Oh, by the way, I mentioned this to some folks and it kind of died. Perhaps some of y'all will study it and post any insights / findings. Open up the SDK direct example that polls the server with php (maybe this is a php issue as you say?). Anyway, leave it run for 3+ hours and watch the memory AND CPU usage of the browser. I found that the CPU usage really throttled my processor after a time.

I remember these exchanges, but have not had time to test :(