Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - process launching a symfony2 command

My goal is to launch some time consuming functions in the background to avoid user to wait before the server response is rendered.

I have a Symfony project where I am launching an asynchronous process from a controller. This process will launch a Symfony command that will call another controller.

The problem is when I am calling the process with start()

$process = new Process('/usr/bin/php '.$this->get('kernel')->getRootDir().'/console scopusftpupload ' . escapeshellcmd($params));
$process->start();

Then nothing happens with the process, but the redirect and some other code that I have later works.

However, if I do

$process->run();

Then the process works fine, but I need to wait until the proceess finished in order to render the view.

Any idea what I am doing wrong?

like image 540
Milos Cuculovic Avatar asked Jul 24 '26 06:07

Milos Cuculovic


1 Answers

I found a workaround to this problem using exec instaed of creating a new Process object.

exec('/usr/bin/php '.$this->get('kernel')->getRootDir().'/console scopusftpupload ' . escapeshellcmd($params) . ' > /dev/null 2>&1 &');
like image 86
Milos Cuculovic Avatar answered Jul 25 '26 19:07

Milos Cuculovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!