Running the Laravel / Symfony / Artisan Command in the Background

I need to run a lengthy Laravel process in the background to use the Streaming Stream API. Effectively the PHP-Artisan CLI command that I need to run is -

nohup php artisan startStreaming > /dev/null 2>&1 &

If I run this myself on the command line, it works fine.

The idea is that I can click on the button on the website that launches the stream by running the long-running artisan command that starts streaming (you need to start in the background because the connection to the Twitter stream never ends). Going through the command line works fine.

Calling a command programmatically, however, does not work. I tried to call it silently via callSilent () from another command, and also tried to use Symfony \ Component \ Process \ Process to run the artisan command or run a shell script that runs the command above, but I can’t figure it out.

Update If I queue with a command that opens a connection to a thread, this leads to a process timeout for the queue worker

I really need a way to execute the above command from the PHP / script class, but where is the PHP script not waiting for the completion / exit of this command.

Help appreciate

+4
source share
2 answers

Symfony , getcwd().

, getcwd(), Laravel (, ), artisan: command not found.

, , , .

public function __construct(
    $commandline, 
    $cwd = null, 
    array $env = null, 
    $input = null, 
    $timeout = 60, array 
    $options = array())

, :

use Symphony\Component\Process\Process;

$process = new Process('php artisan startStreaming > /dev/null 2>&1 &', 'path/to/artisan'); 
$process->start();
+8

Laravels?

0

All Articles