4

This function imports contacts. I would like to launch one process for merging the contacts in background. I'm using the Process class. However, It is not working successfully because when the request returns the response to the client, it kills the process as well. How can I do to keep my process alive after the http request ends?

NOTE: In my localhost works fine but not in my online remote server. Maybe the cause is the php.ini

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

public function importAction(Request $request)
{
    // .....

    //We start the first fusion process
    try {
        $process = new Process('php ' . $this->get('kernel')->getRootDir() . '/console fusion:contact:one_user ' . $user->getId());
        $process->setTimeout(500);
        $process->start();
    } catch (\Exception $e) {
        throw new \Exception($e);
    }

    return ["error" => "0", "message" => "Importation successfully"];
}
luchaninov
  • 6,792
  • 6
  • 60
  • 75
  • Do you use PHP-FPM? If so, you can take advantage of the Symfony [`kernel.terminate` event](http://symfony.com/doc/current/components/http_kernel/introduction.html#the-kernel-terminate-event). – Adam Elsodaney Dec 15 '15 at 18:43
  • How can I use that in according to my case? And what is it happening right now? – Ismael Chuliá Dec 15 '15 at 20:36

0 Answers0