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

eliekhazzaka's avatar

laravel job queue

guys, I have a function I wrote it I put send mail in a job queue how can I configure it on cpanel and keep the php artisan queue:work always run in the background on cpanel?

 public function store(Request $request)
    {
        $rules = [
            'name' => 'required',
            'mobile' => 'required',
            'email' => 'required|email',
            'date' => 'required',
            'employee_id' => 'nullable|exists:employees,id',
        ];

        $this->validate($request, $rules);
        $date = ScheduleCall::where('date', $request['date'])->first();

        if ($date && $request['date'] == $date['date']) {

            return response()->json(['message' => 'date has been already taken']);
        }

        $schedule = ScheduleCall::create($request->all());
        $email['email']= ScheduleCall::orderBy('id', 'desc')
            ->select('email')
            ->first();

        $details =null;
        $job = (new SendEmailJob($email,$details))->delay(Carbon::now()->addSecond(5));
        dispatch($job);


        return $this->showOne($schedule);


    }
0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

unless this is your server, you will be unlikely to be able to install supervisor

The only real solution is to run the queue from the scheduler every minute with the option to quit when empty and then without overlapping on the schedule

This will start the queue worker which will service the queue and then stop. At the next minute it will start again, service the queue and stop

app/Console/Kernel.php

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('queue:work --stop-when-empty')->everyMinute()->withoutOverlapping();
    }

and then setup a cron job in cpanel to run the scheduler once per minute

Please or to participate in this conversation.