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

sdjrppl's avatar

Laravel Schedule running twice using supervisor

  • Laravel Framework 8.11.2
  • PHP Version: PHP 7.4.11
  • Database Driver & Version: MySql 5.7

Description:

Hi, I'm using laradock with php-worker with scheduler configured on supervisor. It's the default configs basically. First I thought it was a bug on my code, then I take drastic measures and removed all, leaving just Log::info calls trying to understand what was causing 2 calls on my commands. So as you can see in the pictures, the schedule method is been called twice. Can someone give me some guidance to prevent this from happening? Thanks

Supervisor

[program:laravel-scheduler] process_name=%(program_name)s_%(process_num)02d command=/bin/sh -c "while [ true ]; do (php /var/www/artisan schedule:run --verbose --no-interaction &); sleep 60; done" autostart=true autorestart=true numprocs=1 user=laradock redirect_stderr=true

Images:

image image

0 likes
12 replies
Snapey's avatar

Why are you trying to call laravel scheduler from supervisor?

This should be done every minute from cron

sdjrppl's avatar

We are using laradock and we have a php-worker container using supervisor to create and manage several workers, including one schedule worker. I can test it like crontab -e, but I believe the result might be the same.

I will test as crontab -e and see if it solves it.

Snapey's avatar

scheduler is not something that you want to keep running. You just fire it once per minute

my guess is that you already have a cron job doing this, hence the double entries

sdjrppl's avatar

But the supervisor config does that while [ true ]; do (php /var/www/artisan schedule:run --verbose --no-interaction &); sleep 60; done

Snapey's avatar

and your approach is working fine !

Sinnbeck's avatar

I assume this in only on your development machine and not production server?

sdjrppl's avatar

@snapey my laradock php-worker container is not working fine, since it dispatches 2 times the scheduler method :D and I was going crazy to understand why I was getting 2 emails for 1 register user :D. I can assure that is just 1 supervisor process running artisan schedule:run with 60 secs interval, but I will follow your approach of using crontab. I did not have time yet to test it, but I will give feedback on it when ready.

@sinnbeck, yes it's just local now, but I'm preparing staging env on AWS and I assume the problem will persist there also.

I've forgot to mention one important thing, it's not homestead laravel project, it's apiato project (which is PORTO pattern on laravel) with tenancyforlaravel package. Maybe (for sure) it's project related, I did not test this yet with a homestead laravel project. I will also test this on standart laravel project, the time is really against me that's the issue xD

Snapey's avatar

Sorry to be critical, you are under pressure to get a working solution but you mess about trying to run the scheduler with supervisor and a sleep statement?

Likely you are running the scheduler twice since sleeping for 60 will be 60 seconds on top of however long it takes the function to run for the first time.

Snapey's avatar

I don't know then. It seems to be a bit of a hack.

codeone's avatar

If the problem still exists, you can check the Laradock's workspace/crontab folder. It runs the scheduler too (along with the supervisor) at every minutes, so it can cause the twice running problem.

1 like
hellohasan's avatar

@sdjrppl hello sir, did you find the solution, today i am also facing this issue i set a supervisor config file where it will run every min, it also run every min but twice, one run the starting of this min and another one run before end of this min. how you protect them.

Please or to participate in this conversation.