473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Server push

Hi all,
I have developed a PHP-based website where a "planner" user can make
up schedules of activities to be performed, storing them into MySQL
tables. Afterwards, other "watcher" users can connect to the website
and retrieve closest task due time, and keep retrieving next task
after each one has been performed.
The problem arises if the planner asynchronously changes the schedule,
e.g. deleting the task "watcher" users consider to be the next one, or
inserting a closer one. How would watchers know, without a cyclic
check on MySQL schedule table about task validity? I would need a sort
of asynchronous server-pushing tecnhique towards watcher's browser
when any schedule modification occurs.
Would you say this could be done with PHP alone?

Thanks a lot in advance

Michelle
Jul 17 '05 #1
8 6687
Michele wrote:
Hi all,
I have developed a PHP-based website where a "planner" user can make
up schedules of activities to be performed, storing them into MySQL
tables. Afterwards, other "watcher" users can connect to the website
and retrieve closest task due time, and keep retrieving next task
after each one has been performed.
The problem arises if the planner asynchronously changes the schedule,
e.g. deleting the task "watcher" users consider to be the next one, or
inserting a closer one. How would watchers know, without a cyclic
check on MySQL schedule table about task validity? I would need a sort
of asynchronous server-pushing tecnhique towards watcher's browser
when any schedule modification occurs.
Would you say this could be done with PHP alone?

Thanks a lot in advance

Michelle


Hi Michelle,

My first response would be: "Let the planners think before they shedule."
That would save you a lot of trouble, wouldn't it?
Anyway, this is the real world.

No such thing as real serverpush with PHP to my knowledge, but if your
browser is open during the task of your 'watcher-users', you can let the
browserwindow periodically check the server and ask if the task is still
valid.
If this is what you call "cyclic check on MySQL schedule table" then I think
you cannot work around it.

This can easily be accomplished by using a frameset, and make one frame
invissible. In that frame you call a php-script that checks the validity of
the task, and when it is not valid, you can return code that for example
creates a javascript allert.
I hope this helps. :-)

Good luck and regards,
Erwin Moller
Jul 17 '05 #2
Hi Erwin,
I know the "hidden" periodic check on the server would be the easiest
solution. The hard part would be the tuning of periodicity interval.
Actually, I've been thinking about a different solution, exploiting
PHP socket functions: I would have a server socket open in the
"hidden" frame, waiting for update alerts. Any time a change in the
schedule is performed by planner users, a PHP script could connect to
the socket, triggering a refresh of the task list page by the watcher
user.
Although this could save the day, it sounds sort of a dirty trick to
me. I would seek a cleaner solution first (if available).

Michelle

Erwin Moller <si******************************************@spam yourself.com> wrote in message news:<3f***********************@news.xs4all.nl>...
Michele wrote:
Hi all,
I have developed a PHP-based website where a "planner" user can make
up schedules of activities to be performed, storing them into MySQL
tables. Afterwards, other "watcher" users can connect to the website
and retrieve closest task due time, and keep retrieving next task
after each one has been performed.
The problem arises if the planner asynchronously changes the schedule,
e.g. deleting the task "watcher" users consider to be the next one, or
inserting a closer one. How would watchers know, without a cyclic
check on MySQL schedule table about task validity? I would need a sort
of asynchronous server-pushing tecnhique towards watcher's browser
when any schedule modification occurs.
Would you say this could be done with PHP alone?

Thanks a lot in advance

Michelle


Hi Michelle,

My first response would be: "Let the planners think before they shedule."
That would save you a lot of trouble, wouldn't it?
Anyway, this is the real world.

No such thing as real serverpush with PHP to my knowledge, but if your
browser is open during the task of your 'watcher-users', you can let the
browserwindow periodically check the server and ask if the task is still
valid.
If this is what you call "cyclic check on MySQL schedule table" then I think
you cannot work around it.

This can easily be accomplished by using a frameset, and make one frame
invissible. In that frame you call a php-script that checks the validity of
the task, and when it is not valid, you can return code that for example
creates a javascript allert.
I hope this helps. :-)

Good luck and regards,
Erwin Moller

Jul 17 '05 #3
Michele wrote:

Hi Michele,
Hi Erwin,
I know the "hidden" periodic check on the server would be the easiest
solution. The hard part would be the tuning of periodicity interval.
Why? You could do it every 30 seconds or so?
But of course I don't know all your requirements, so .... :-)
Actually, I've been thinking about a different solution, exploiting
PHP socket functions: I would have a server socket open in the
"hidden" frame, waiting for update alerts. Any time a change in the
schedule is performed by planner users, a PHP script could connect to
the socket, triggering a refresh of the task list page by the watcher
user.
Please be aware of the fact that many people have only a few port to open
because of firewalls.
And browsers have time-outs, so if you let the frame 'wait' for the socket
to respond, I wouldn't be suprised to find it closed soon.
Although this could save the day, it sounds sort of a dirty trick to
me. I would seek a cleaner solution first (if available).

Keep me (us) informed of your solution!

Regards,
Erwin Moller
Michelle

Erwin Moller
<si******************************************@spam yourself.com> wrote in
message news:<3f***********************@news.xs4all.nl>...
Michele wrote:
> Hi all,
> I have developed a PHP-based website where a "planner" user can make
> up schedules of activities to be performed, storing them into MySQL
> tables. Afterwards, other "watcher" users can connect to the website
> and retrieve closest task due time, and keep retrieving next task
> after each one has been performed.
> The problem arises if the planner asynchronously changes the schedule,
> e.g. deleting the task "watcher" users consider to be the next one, or
> inserting a closer one. How would watchers know, without a cyclic
> check on MySQL schedule table about task validity? I would need a sort
> of asynchronous server-pushing tecnhique towards watcher's browser
> when any schedule modification occurs.
> Would you say this could be done with PHP alone?
>
> Thanks a lot in advance
>
> Michelle


Jul 17 '05 #4
Michele wrote:
Hi all,
I have developed a PHP-based website where a "planner" user can make
up schedules of activities to be performed, storing them into MySQL
tables. Afterwards, other "watcher" users can connect to the website
and retrieve closest task due time, and keep retrieving next task
after each one has been performed.
The problem arises if the planner asynchronously changes the schedule,
e.g. deleting the task "watcher" users consider to be the next one, or
inserting a closer one. How would watchers know, without a cyclic
check on MySQL schedule table about task validity? I would need a sort
of asynchronous server-pushing tecnhique towards watcher's browser
when any schedule modification occurs.
Would you say this could be done with PHP alone?


I've looked into this extensively as I really could do with something of
the sort. My findings were:

1. server push is exactly what the doctor ordered but Netscape
(Mozilla?) only.

2. you can arrange polling through some combination of meta-refresh or
javascript. This can leave the main displayed page unaffected with
iframes or a frameset. I often do this by creating a frameset with a
'connection bar' across the bottom of the document. This is refreshed
periodically and any delivered instance may contain javascript to modify
or reload the main page. As you say though, the timing of this is an
issue. I sometimes have to defer links and submits through a reload of
the connection bar to ensure that the requested action is still valid.

3. if you really want to reproduce server push you will need an activex
or java applet which leaves open a socket to your server. However quite
a lot of firewalls and proxies will stamp all over this and time the
connection out.

If anyone has any better ideas then I am all ears

Kevin Thorpe
Head of IT
Purchasing Index (UK) Ltd

Jul 17 '05 #5
well, firewalls or proxies are not an issue here, since the I'm
working within my company Intranet, so I should have any port
available.
On the other hand, I admit my ignorance about browser timeout. I
didn't know about this other aspect. What's the default value? and (of
course) is there any way to change it? After all, this timeout could
affect my "hidden" refresh as well if I set my refresh rate too large,
coudn't it?

Michelle

Kevin Thorpe <ke***@pricetrak.com> wrote in message news:<3f***********************@news.easynet.co.uk >...

I've looked into this extensively as I really could do with something of
the sort. My findings were:

1. server push is exactly what the doctor ordered but Netscape
(Mozilla?) only.

2. you can arrange polling through some combination of meta-refresh or
javascript. This can leave the main displayed page unaffected with
iframes or a frameset. I often do this by creating a frameset with a
'connection bar' across the bottom of the document. This is refreshed
periodically and any delivered instance may contain javascript to modify
or reload the main page. As you say though, the timing of this is an
issue. I sometimes have to defer links and submits through a reload of
the connection bar to ensure that the requested action is still valid.

3. if you really want to reproduce server push you will need an activex
or java applet which leaves open a socket to your server. However quite
a lot of firewalls and proxies will stamp all over this and time the
connection out.

If anyone has any better ideas then I am all ears

Kevin Thorpe
Head of IT
Purchasing Index (UK) Ltd

Jul 17 '05 #6
Michele wrote:
well, firewalls or proxies are not an issue here, since the I'm
working within my company Intranet, so I should have any port
available.
On the other hand, I admit my ignorance about browser timeout. I
didn't know about this other aspect. What's the default value? and (of
course) is there any way to change it? After all, this timeout could
affect my "hidden" refresh as well if I set my refresh rate too large,
coudn't it?


I've looked for settings to affect browser timeouts, even delving
through the registry and cannot find any (for IE). I do know that it
appears to give up after a while. It's quite a long delay anyway.

In reality you will be polling the server at fairly regular intervals
and the server side query and reply should be very quick and short. I
usually have the main page include a timestamp which is passed in the
url to the 'check changed' frame. The return value is either a blank
document or a single line of javascript to refresh the parent/opener.

Your real problem here is stopping someone choosing a task which has
been taken after the last page load. I'v got an idea but I've got to go
now. I'll give you further information tomorrow.
Jul 17 '05 #7
Sorry about yesterday, I was really unwell. Anyway I promised to explain
further on how to sort your problem out.

Use a frameset.
+---------------------------------------------+
| <main> main page with list of tasks |
| |
| |
| |
| |
| |
+---------------------------------------------+
| <query> single row to perform queries in |
+---------------------------------------------+

The main page should display the current table of tasks to select from.
These links should call javascript to ask the query page to select a task:
<script language=javascript>
function choosetask(tasknum) {
window.parent.query.location.href='query.php?choos etask='+tasknum;
}
</script>
<a href='' onClick='choosetask(<?=$tasknum?>); return false;'>Choose</a>

The query page should do two things. Firstly it should refresh itself
periodically to see if the database has changed. If it has then it
should refresh the main page. Secondly, if it has been asked to choose a
task then it should check if that task is still available.

<?php # get the last update time
$result = mysql_query("SELECT lastupdate FROM STATUS");
$row = mysql_fetch_assoc($result);
$lastupdate = $row['lastupdate'];
if ($lastupdate > $_REQUEST['lastupdate']) {
$reload = true;
}
?>
<html>
<head>
<meta http-equiv=refresh content="20;
url='http://www.server.com/query.php?<?=$lastupdate?>'">
</head>
<body>
<?php if ($_REQUEST['choosetask']) {
# we've been asked to choose a task
$result = mysql_query("UPDATE TASKS SET status='busy' ".
"WHERE ID=$_REQUEST[choosetask] ".
"AND status='free' ");
if (mysql_num_rows() == 1) {
# update worked, you have the task
$result = mysql_query("UPDATE STATUS SET lastupdate=NOW()");
echo "<script language=javascript>\n".
"alert('You have the task');\n".
"window.parent.main.location.reload();\n".
"</script>\n";
} else {
# failed - task missing or taken
echo "<script language=javascript>\n".
"alert('Sorry, that task has already been taken');\n".
"window.parent.main.location.reload();\n".
"</script>\n";
}
} else {
# just a refresh - check if database has changed
if ($reload) {
echo "<script language=javascript>\n".
"window.parent.main.location.reload();\n".
"</script>\n";
}
} ?>
</body>
</html>

This way you get a check when you try and select a task to avoid double
selecting. Of course you will occasionally get a 'sorry' on selecting a
task, but this seems the easiest way to do things.

I hope this helps.

Jul 17 '05 #8
Yes, I was thinking about something similar myself too:
- Whenever the "watcher" user first starts, "main" frame queries the
server for the closest task in schedule, and then implements a
javascript-based countdown for that task itself.
- The "hidden" frame refreshes itself every 20-30 seconds (should be
enough to avoid browser timeout, I hope), asking the server about
validity of its current closest task. If task is not valid anymore,
this frame orders a refresh of "main" frame, which queries the task
schedule again and updates the countdown.
- If a "planner" user changes the schedule, the watcher will know as
soon as next "hidden" frame refresh occurs; "planner" user will not be
allowed to delete a task if it is "too" close (configurable), just to
make sure a task is not deleted when it is about to be performed (the
whole environment is synchronized though NTP).

So, I seem to surrender to periodic page refresh, if no other reliable
solution exists. Too bad...
Thanks again for your suggestions

Michelle

From: Kevin Thorpe [mailto:ke***@pricetrak.com]
Sent: venerd́ 31 ottobre 2003 12.06

To: Betti Michele
Subject: Re: Server push

Sorry about yesterday, I was really unwell. Anyway I promised to explain further on how to sort your problem out.
Use a frameset.
+---------------------------------------------+
| <main> main page with list of tasks |
| |
| |
| |
| |
| |
+---------------------------------------------+
| <query> single row to perform queries in |
+---------------------------------------------+

The main page should display the current table of tasks to select from.
These links should call javascript to ask the query page to select a task:
<script language=javascript>
function choosetask(tasknum) {
window.parent.query.location.href='query.php?choos etask='+tasknum;
}
</script>
<a href='' onClick='choosetask(<?=$tasknum?>); return false;'>Choose</a>

The query page should do two things. Firstly it should refresh itself
periodically to see if the database has changed. If it has then it
should refresh the main page. Secondly, if it has been asked to choose a
task then it should check if that task is still available.

<?php # get the last update time
$result = mysql_query("SELECT lastupdate FROM STATUS");
$row = mysql_fetch_assoc($result);
$lastupdate = $row['lastupdate'];
if ($lastupdate > $_REQUEST['lastupdate']) {
$reload = true;
}
?>
<html>
<head>
<meta http-equiv=refresh content="20;
url='http://www.server.com/query.php?<?=$lastupdate?>'">
</head>
<body>
<?php if ($_REQUEST['choosetask']) {
# we've been asked to choose a task
$result = mysql_query("UPDATE TASKS SET status='busy' ".
"WHERE ID=$_REQUEST[choosetask] ".
"AND status='free' ");
if (mysql_num_rows() == 1) {
# update worked, you have the task
$result = mysql_query("UPDATE STATUS SET lastupdate=NOW()");
echo "<script language=javascript>\n".
"alert('You have the task');\n".
"window.parent.main.location.reload();\n".
"</script>\n";
} else {
# failed - task missing or taken
echo "<script language=javascript>\n".
"alert('Sorry, that task has already been taken');\n".
"window.parent.main.location.reload();\n".
"</script>\n";
}
} else {
# just a refresh - check if database has changed
if ($reload) {
echo "<script language=javascript>\n".
"window.parent.main.location.reload();\n".
"</script>\n";
}
} ?>
</body>
</html>

This way you get a check when you try and select a task to avoid double
selecting. Of course you will occasionally get a 'sorry' on selecting a
task, but this seems the easiest way to do things.

I hope this helps.

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Bradbury | last post by:
I want to send updates from a long running cgi. I have tried copying perl examples of server push and can not get them to work. Does anyone have an idiot proof example of a working server push or...
7
by: DW | last post by:
Hi, Here is my question. I want to push security prices to the desktop from the server. Whenever there is a new price in the database, the server notifies the client. How can this be done in...
3
by: Ben Kim | last post by:
Hello all, We are interested in having a server push data down to the client on a periodic basis (IE data change). This data would need to be pushed into a grid control. We do not want to...
6
by: Martin Holmgaard | last post by:
I have written the following function to be used for flood filling in a bitmap. The function works fine on Windows XP Prof and Windows 2000 server, but on Windows 2003 server it return a stack...
4
by: batista | last post by:
Hello All, my prob. is that i have a web server, and i want it to send fresh data,whenver it is available(from sum other source), to a webpage. Now i used refresh, but i want to use an...
1
by: Rodney | last post by:
I want to notify browser of every time my server side event fires w/o creating some sort of timer on client. Basically, can server notify client w/o client initiating contact? Again, thx for any...
0
by: Crisco www.misericordia.com.br | last post by:
Hi I m working on WEBRADIO Software. im using Windows media encoder 9 SDK on Windows 2003 server using VB.NET. My current scenario is my soundcard . My application will push my server the...
5
by: Mark Goldin | last post by:
Can I create a push server using ASP technology? Thanks
0
by: davy zhang | last post by:
import asyncore, asynchat import os, socket, string PORT = 8000 class HTTPChannel(asynchat.async_chat): def __init__(self, server, sock, addr): asynchat.async_chat.__init__(self, sock)...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.