Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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
    Michele Guest

  2. Similar Questions and Discussions

    1. Blazeds server push and multiple flex instances
      I am working on a project to push data from a server to a flex chart drawing application. However each chart needs to run as its own page. Up til...
    2. How to push realtime data from SQL Server
      Hello, I am looking for the best way to approach the following situation ... 1) how to connect 2) what I will need to maintain "realtime"...
    3. Can you push XML data with Media Server 2
      Can you use Media Server 2 to PUSH just regular data to a SWF say like XML data sent every second? THX Kevin
    4. Server PUSH to client
      We have an internal asp.net application for orders/manufacturing information. Presently we have set the META Refresh tag on the affected pages set...
    5. how to do a server push
      At a certain page in my web app I'm entering users into a Queue for processing, how can I do a server push (like the expedia 'searching for...
  3. #2

    Default Re: Server push

    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
    Erwin Moller Guest

  4. #3

    Default Re: Server push

    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 <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in message news:<3f97daf3$0$58716$e4fe514c@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
    Michele Guest

  5. #4

    Default Re: Server push

    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
    > <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
    > message news:<3f97daf3$0$58716$e4fe514c@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
    >>
    Erwin Moller Guest

  6. #5

    Default Re: Server push

    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

    Kevin Thorpe Guest

  7. #6

    Default Re: Server push

    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 <kevin@pricetrak.com> wrote in message news:<3f9e8ec7$0$23331$afc38c87@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
    Michele Guest

  8. #7

    Default Re: Server push

    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.


    Kevin Thorpe Guest

  9. #8

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

    Kevin Thorpe Guest

  10. #9

    Default Re: Server push

    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:kevin@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.
    Michele Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139