-2

I would like to create for myself a base core (or package) for handling interactions between the server side and client side. My approach is this:

  • Set the time interval to every two seconds (arbitrarily picked)
  • Create a script on the PHP side. This script will allow other PHP scripts to add functions to call (or remove them) to collect information that will be sent to the client.
  • Every 2 seconds, the client will call this PHP script to request the information.
  • When this occurs, the PHP script will call all added functions, store their data, and send all data back to the client.
  • The client will handle this data appropriately

I am not sure if this actually describes an implementation of the Push-Pull model, or of a similar, but different, model. I imagine the "pushes" from the client to the server side would not need to be synchronized into this two second window.

The ultimate goal in all of this is for me to create a method in which the client side can remain up to date when displaying information that is likely to change while the browser window is open.

I would like to ask if this is a correct interpretation of the push pull model, if this is a suitable way to accomplish this goal, and if there is possibly a more suited paradigm for this goal.

Brandon Dixon
  • 1,036
  • 9
  • 16
  • 2
    looks like all pull and no push. yor client side is just polling the server side on a timed basis –  Dec 04 '17 at 20:37
  • I see your point. I imagine that the client side would be free to push at any point, rather than being in the 2 second window. If this were the case, would it still be a push/pull paradigm, or something else entirely? – Brandon Dixon Dec 04 '17 at 20:41
  • the server should be pushing when it gets new data. –  Dec 04 '17 at 20:42

2 Answers2

2

Push: The SERVER side actively sends information to the client (via WebSocket). Therefore, the client passively listens for messages of the server.

Pull: The CLIENT requests actively information from the server (via HTTP or WebSocket). The server processes the request and sends the requested information back.

What you want to achieve is the PUSH. Although, you try to implement this via longpolling (where the client gathers his infos actively).

If you really want to implement your approach, get yourself into WebSockets. You can see a basic example on https://socket.io/ unfortunately this is nodeJs and not PHP.

sebastian
  • 813
  • 1
  • 7
  • 14
  • The 2 second check was my way of simulating a PUSH. I'll take a look at the web socket, as that looks more true to this paradigm. – Brandon Dixon Dec 04 '17 at 20:52
0

PHP supports server sent events which sounds suitable for what you are trying to achieve

miknik
  • 5,748
  • 1
  • 10
  • 26