2

I have a html form with some fields that are linked to a database row that have to be modified at the same time by different users.

Every time one of the users edit an input field it may call a javascript onchange (or similar) function to update the specific column in the row, but the other users that have the same page opened don't see the change until they refresh the page. What should I use to get it changed on all devices that are looking the page?

The backend is in PHP/MySQL.

Thank you

3 Answers3

1

You have a way to send pushes to your backend server but now you need to get pulls from your server.

For this purpose, you need to maintain a constant communication channel between your client and server to get real time updates from your server. There are multiple options for this:

  • Websockets: A TCP websocket can be used for real time communication between server and client. See this thread to get more information about websocket support in PHP.
  • Polling (very dirty way): you can do frequent poll from your client to your server to see if there has been any updates or not. This way of implementation is really inefficient and not recommended at all but still, since some applications already have polls in their system, if your system is already doing frequent polls, you can attach the query to get form status with that poll.
Community
  • 1
  • 1
Rax
  • 785
  • 4
  • 14
0

When you look for some already existing tools, this might something for you: https://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesFormSync/docs/reference.html

When you do not find anything that matches your needs, you can write it on your own. Therefore you need Ajax (To transfer a change to the server), it is more easy to use in combination with jQuery. http://www.w3schools.com/jquery/jquery_ajax_intro.asp And you can also fetch the data from the server with ajax, but you have to do requests all the time, which is not very nice. An alternative would be websocket, but this need a lot of knowledge.

Unlikus
  • 1,419
  • 10
  • 24
0

There are a couple of possible approaches.

  1. Have an ajax request in the client periodically poll the web server to retrieve the data. Though depending on how this is implemented, there could be some performance ramifications.

  2. You could benefit from using WebSockets. Since you're using PHP and MySQL you might look into something like Ratchet. Depending on how far along the code base is you could potentially implement something with socket.io using node.

jhdielman
  • 16
  • 3