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...
}
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...
}