akmadhwa's avatar

Running artisan command in background

I run the artisan:call via controller and calling it from button in frontend. What if the data that is being run using artisan:call is huge and cause the frontend to be abort.

For this issue how to maintain the command to be run in background and keep on running until the process in handle is done even the php is already timeout or abort.

Thank you.

0 likes
6 replies
ykchan's avatar

Not sure if this work, but under Linux environment, you can try append an '&' to the command, e.g. shell_exec('your-artisan-call &').

In Windows environment, you may need to use shell_exec('START /MIN your-artisan-call')

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

This is the whole point of queues

https://laravel.com/docs/6.x/queues

Queues allow you to defer the processing of a time consuming task, such as sending an email, until a later time. Deferring these time consuming tasks drastically speeds up web requests to your application.

akmadhwa's avatar

Thank you for replaying. I got my answer already just use the queue like how the documents shows.

Sinnbeck's avatar

Please mark a best answer to set the thread as solved

lbeygi.m's avatar

Hi

you can used proc open for run in background.

Such as :

$descriptionProcOpen = [
    ["pipe", "r"],
    ["pipe", "r"],
    ["pipe", "r"]
];

proc_open("php " . base_path() . "/artisan artisan:command", $descriptionProcOpen, $pipes);

Please or to participate in this conversation.