Moisés Moisés - 3 months ago 57
PHP Question

Laravel 5.2 run command as daemon/forever

Once I have a command method, this one, it is possible to keep that commad running forever?

So far I have an ajax that calls for

\Artisan::queue('socket:start');


'socket:start' is my command.

That does work, but only for 30 seconds. After that my process dies.

I tried to run as daemon process, as laravel documentation says but no luck.

How can I give the user the option to run my command, and keep it alive in background forever?

Answer

You're running into that problem because the apache version of PHP has a timeout. By default the CLI version does not, so you can use PHP's exec() function to run the artisan command which should work:

exec('php artisan socket:start');

As usual, only use this if you know exactly what is going into exec().