-1

I have a PHP & MySQL website and I want to synchronize some event on it

Example:

We have two pages: colors.php, manageColors.php We have three users: user1, user2, user3

user1 and user3 open colors.php page, the color now they are seeing is red

User3 open manageColors.php and he change the color to purple

user1 and user2 directly without refreshing the page the color in colors.php changes to purple.

Please does anyone have any clue how to do it? Even if Php & MySQL isn’t enough to achieve this, guide me to another programming language that is able to.

I tried to create a table in my db that holds the color that is chosen by the user3

Colors.php will show the value of the table

manageColors.php has a form to change the value of the color

user1 and user2 has to refresh their page on colors.php to get the new value of color

  • Poll your server every X seconds to fetch newest data using Ajax – Justinas Aug 30 '23 at 19:49
  • "directly", "not refreshing the browser"... HTTP is badly suited for this requirement tbh – Honk der Hase Aug 30 '23 at 19:50
  • 1
    Or use [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) – Justinas Aug 30 '23 at 19:51
  • When someone changes the color, update the database. Use AJAX to periodically call an API that returns the color from the DB. – Barmar Aug 30 '23 at 19:51
  • @Justinas PHP is poorly suited as a websocket server. – Barmar Aug 30 '23 at 19:52
  • @HonkderHase weird that the web runs on that and seems quite capable of doing it. For the last decade or so it's basically been the expectation, as well with SPAs and all sorts of dynamic pages. The page you're looking right now would be changing without requiring a full refresh. – VLAZ Aug 30 '23 at 19:52
  • 1
    Simple solution: Put all three users in front of the same display. Then they can also communicate how much they love users-3 choice of colour. – hakre Aug 30 '23 at 19:53
  • @Justinas PHP has FCGI, all users could subscribe to an event stream, no websockets needed. – hakre Aug 30 '23 at 19:55

0 Answers0