I am planning a website with an html/javascript frontend input and a php backend. The user has to input data which will be saved in a database. Now I want to inform the other users of my site accordingly about the changes made on the database.

Is this possible in any way (at this point of planning I cannot say how many people will use this in the end so it has to be a user friendly option).

The concept I have is following: I type in a message like Hello then the other user should be informed about the fact that the last word was Hello so that they can add a new word like World. But the fact that some user are faster than others the word will be fastly outdated. So i have to find a solution for that.

Any suggestions or is my question unclear?

  • Is this conceptually different from a realtime chat on a website? – Ordous Aug 6 '15 at 13:08
  • @Ordous hmm, thats a good point. but PHP and realtime? :D or should I use Websockets? – Snickbrack Aug 6 '15 at 13:10
  • I honestly don't know how those things are implemented. But if it looks like something close to what you need - then the answer is an obvious "yes" with a direction to look in (even though it may not be entirely suitable or the easiest solution) – Ordous Aug 6 '15 at 13:17
  • or is it a good solution to ignore the ouddated requests? so only accept the first word and ignore the following sent words for the old shown word. is this suitable for a good user experience? – Snickbrack Aug 6 '15 at 13:20
  • That depends on what your system is. There is inherently some concurrency when multiple users do things in real time. What will you do if someone posts 0.1 seconds before a user hits "Enter"? Same thing can be done if someone posts in the 0.5 second period while you poll for the latest state. It's perfectly acceptable to just not do anything in chats. Stuff like managing something important will likely refuse the entire operation to play safe. Some will accept the update but allow you to make retroactive changes. This is more to do with UX rather than software design though. – Ordous Aug 6 '15 at 13:34

Your best bet for this if your intended clients have sufficiently modern web browsers is Web Sockets. There are plenty of libraries out there that you can use and can look into. The one I have used most recently for PHP projects is Pusher, but searching for 'PHP websockets' turns up plenty of libraries and code samples you could use.

  • Found Fleck. What is exactly what I wanted, thanks. – Snickbrack Aug 7 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.