Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mtbossa's avatar

Best approach for scheduling event on post start and end date

I'm developing some kind of real-time post displaying application with Laravel, and I can't seem to find a good approach for what I need.

The end user can create posts with specific start and end date/time, and I need to notify the client (frontend) when a post should start showing, and when should stop as well (e.g., post should start 2022-05-05 10:00:00 (notify frontend at this time), end at 2022-05-05 18:00:00 (notify frontend at this time)). These notifications should be send really fast.

I know I could schedule a task using Laravel Task Scheduling that runs every X seconds and checks all the posts start/end dates and then notify, however I don't know if this is the best approach. Do you have any other suggestions or technologies I could use?

0 likes
6 replies
jdc1898's avatar

Use Laravel Event/Listener system and either Echo or Pusher to broadcast the events to the front end. I’ve done what you’re describing using both the scheduler and events.

2 likes
mtbossa's avatar

@jdc1898 the problem is that I need to schedule the post start/end, so when current time hits the post start time, this notification will be send.

jdc1898's avatar

@mtbossa

Yep! Use Carbon to check against the post_start and post_end timestamps within your listener and you're good to go. Otherwise, you're going to have to create a boolean field on the post model isActive or something like that to check against.

mtbossa's avatar

@jdc1898 Ok, so you are telling me that the approach I said I was going for (keep running a task that checks dates/times is a good approach? Actually, I winded up using Laravel Job Delay system, I calculate the diff until next Post Start, then use Notification system to a WebSocket connection.

jdc1898's avatar

If you’re on Laravel 9, the approach @axeloz mentions is a great approach as well.

Please or to participate in this conversation.