Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to trigger server-sent event in HTML5 ... OR : Can PHP script be aware if another script has been called?
    primarykey
    data
    text
    <p>Now that all of the browsers I like have almost full support for Server Sent Events, I wanted to try implementing it on a site I've been putting off because I hate polling. But I have initial hesitation that I was hoping I could get some help on.</p> <p>Here is my use case:</p> <p>User goes to a form, something time-based and competitive, in this case class registration. All things being equal, they have a list of about 30 - 40 classes they are eligible for, and in order to minimize instances of "she logged in first but he hit save first but he didn't mean to hit save but she already chose another class" etc, I want to make the form real-time, so that when someone selects an option, it goes straight into the db and anyone else viewing the form sees that it is filling up. (I'll deal with the stress of people changing their minds later).</p> <p>So, in a polling scenario, I had to deal with the AJAX calls having to check on the status of 40 spots and update them and setting an interval that could potentially still create collisions.</p> <p>But with Server Sent Events, I can have the listener get just the spots that need updating, which seems better, but here's where I get stuck:</p> <ol> <li><p>Is there any risk of the listener getting overloaded? Let's say the script sends 15 messages, back-to-back, about a status change. I see vague mentions of how user agents should handle queued tasks, but it's not clear if that's for establishing a connection or handling server-sent messages</p></li> <li><p>Is this basically just passing the burden of polling from the browser to the server? Does the script have to check the DB every second for changes? Is there any way for the script to be aware or notified when change has occurred? Let's assume that seat requests are sent to <code>requests.php</code> via ajax and that <code>updates.php</code> pushes events back to the browser. Is there a standard and/or clever way for <code>updates</code> to idle until <code>requests</code> has made a commit?</p></li> </ol> <p>The only solution I can think of is for <code>requests.php</code> to write the committed changes to a flat file (<code>commits.xml</code> perhaps) and <code>updates.php</code> just polls the file size every half-second, thereby keeping the workload to a minimum.</p> <p>Any better/smarter/more obvious solutions out there? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload