0

I have a PHP website and a SQL database. Users will be able to update this data with a mobile phone. I would like all users to receive these updates. How would I do this?

I could simply use ajax and a timer to have each client request updates at a given interval.

Is there a way to set a callback of sorts so that a service on the server calls a list of method instances? This would prevent unnecessary requests and transfer of data...

P. Avery
  • 779
  • 1
  • 16
  • 34

2 Answers2

2

If you don't want to use a third-party solution like the one @Alexandre Martin suggested, you could use Server Sent Events. The flow is as follows:

  1. Each user subscribes to a channel (think of it as registering an event listener on a connection). On the server side, a script is running continuously to track for changes
  2. A user posts an update to the server.
  3. The script notices the update and issues an event
  4. All clients who subscribed to the channel receive the event, read its data property and update their local models.

See this introduction, with sample PHP implementation.

You could also use Web Sockets. Here is a comparison of the two. Before implementing either, consider browser compatibility.

Community
  • 1
  • 1
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165
0

You can use Firebase to create an online database and to send upload and download messages from and to clients as soon as an internet connection is detected (also called Cloud messaging)

SQLite manages offline operations directly on the device and is synchronized with Firebase automatically.

Look at the Get started page and you will find web, iOS and Android tutorials. http://firebase.google.com

Alexandre Martin
  • 1,472
  • 5
  • 14
  • 27