Home > database >  Laravel call to controller method from command line to run in background
Laravel call to controller method from command line to run in background

Time:02-16

I have method in laravel controller with some logic that need to run in the background in an infinite loop. With core php with was simple as we used to set it nohup php and call the php file to run in the background. How could we do the same with laravel to run the things in background.

Note: I cannot use cronjob for this as its an infinite loop which need to kept running in the background

CodePudding user response:

Kinda hard to imagine what task you want to accomplish, but you could create laravel command, which could call controller method directly.

How to call controller method from within command

Check comment under the answer to resolve controller correctly.

Next, you should run command by the supervisor.

Supervisor tutorial

CodePudding user response:

you can use define cronjob on your linux machine or use laravel schedule library . look at the following link :

https://laravel.com/docs/5.1/scheduling

  • Related