0

I have now created a controller and an endpoint that users call every few seconds to make sure they are online. At each call, I save the time of their last visit, and if no request is made to the user beyond the specified time, the user is considered offline. What I'm looking for now is for an event to run and broadcast a message when a user does not send any request beyond the specified time.

What is clear is that when an user is offline, no event is called and as a result nothing is done.

Several ways came to my mind to solve this problem and I finally decided to ask a question here.

  1. Call an artisan command every few seconds using different methods (such as daemon). That command gets the list of users who did not call the online endpoint beyond the specified time. And puts a broadcast in the queue list for each user who goes offline.
  2. Instead of calling continuously, use commonly called endpoints (such as the home page) to periodically call commands.

Is there a better way to do this?

user14818231
  • 1
  • 1
  • 3
  • If you want to check if the user is online or not it is better to use a websocket. If you want to broadcast messages to all user who is not online the artisan command with cron would be good if you don't need to check more than 1 time per minute otherwise this command should be run as service. If you need service you can create a systemd unit for this PHP artisan command and than manage it from monit service manager or use supervisord – Alexandr Blyakher Apr 12 '21 at 08:44
  • An event occurred when the user visited, but no event occurred when not visiting. So the basis of the method you mentioned is the only possible way to do this. A service with a specific schedule is run by supervisord and counts users who have not had any activity for a certain period of time and broadcasts the result to the frontend. – user14818231 Jun 22 '21 at 10:28

0 Answers0