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

ShamiCanCode's avatar

Laravel Refresh after every 3 minutes

My website is a prediction app in which users predict a particular number to win the game.

Now My website has game periods and each period is 3 minutes. Now in one day, there are 1440 minutes and 1440/3= 480 which means there are 480 periods in one day.

How I achieve this?

0 likes
34 replies
ShamiCanCode's avatar

@vincent15000 yes You understand but on the other hand after every 3 minute period update and particular function run

1 like
vincent15000's avatar

@ShamiCanCode Livewire is an extension of Laravel and it uses blade templates too.

Livewire allows you to add reactivity in your application without refreshing the page and you code this only with PHP.

Sinnbeck's avatar

@ShamiCanCode Or you can use plain javascript

setTimeout(function() {
    //ajax request to get new data and do stuff with it
}, 3000)
1 like
vincent15000's avatar

@ShamiCanCode It will execute the function every x minutes only if a user open a page. If you need to setup an update server side, it has to be done another way.

1 like
ShamiCanCode's avatar

@Sinnbeck Yes this is I am looking for Can I do after every three minutes run a particular controller function in task scheduling

1 like
vincent15000's avatar

@ShamiCanCode Ok I think that I begin to understand what you need.

On the server you want to execute some function every x minutes and automatically refresh the page for each user.

This can be done as @sinnbeck told you with a scheduled job and then you can broadcast an event to refresh all screens.

Sinnbeck's avatar

@ShamiCanCode You dont run controllers. Those are for http requests. You run a command or a job. But you just schedule it evey 3 minutes

$schedule->call('calculate:stuff')->everyThreeMinutes();
1 like
vincent15000's avatar

@ShamiCanCode I just participated to the conversation, I let you with @sinnbeck, he is a great developer ;), you will have the best advice with him.

I will go for a walk now, there is a wonderful sun today and it's not too cold.

ShamiCanCode's avatar

@Sinnbeck @vincent15000 let me tell you my requirement I want a website which executes a particular function (algorithm) every three minutes. Now I have two scenarios

  1. User is on that page where results are shown which is done by plain js polling function
  2. On server every three minutes the algorithm run
1 like
Sinnbeck's avatar

@ShamiCanCode You could cache the result using the scheduled job and then each client does polling every 3 minutes and get the cached result. But it can be a bit off, as they dont start 100% the same time. Or you can dispatch a broadcast using websockets which updates all clients (But this is a bit harder to set up)

2 likes
ShamiCanCode's avatar

@Sinnbeck I know about websockets.

task scheduling every three minutes Job executed and when job executed call a websockets to refresh a page.

what do you say?

1 like
Sinnbeck's avatar

@ShamiCanCode Yeah but if its not a ton of data, the websocket message could just contain the new data, and just add it to the page using javascript :) No need to reload then

1 like
Sinnbeck's avatar

@ShamiCanCode ok. Then be sure to cache it then (or put it in the database). And if the user interacts with the page, its best to use ajax, instead of reload.

2 likes
ShamiCanCode's avatar

@Sinnbeck

$schedule->call(function () {
            Check::create([
                'check' => 12
            ]);
        })->everyMinute();

It is not creating data in model

Please or to participate in this conversation.