Symfony Process 'stop' method doesn't work

304 views Asked by At

I have this code:

$process = Process::fromShellCommandline('bash ./receive.sh \
    url=' . env('SGW_URL') . ' \
    cert=certs/privateKey.p12?' . env('SGW_CERT_PASS'),
        '/var/www/sgwClientFiles/');

    $process->run();
    $process->getCommandLine();
    if (!$process->isSuccessful()) {
        throw new ProcessFailedException($process);
    }
    
    $process->stop(15);

    return $process;

and it doesn't stop after 15sec. Instead, I get 'exceeded the timeout of 60 seconds' error.

The thing is, that a command which I try to run from command line doesn't stop itself and it has to be stopped from the script. Any ideas why the method "stop()" doesn't function properly?

1

There are 1 answers

0
Mr_T On

If anyone wonders, I solved this issue as follows:

$process->start();
    while (time() - $process->getStartTime() <= 15) {
        usleep(2000);
    }

    $process->stop();