By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,825 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,825 IT Pros & Developers. It's quick & easy.

Server push

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.