8000 Is Symfony process component work different between Linux and Max OS X? · Issue #20445 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Is Symfony process component work different between Linux and Max OS X? #20445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TonyGao opened this issue Nov 8, 2016 · 9 comments
Closed

Comments

@TonyGao
Copy link
TonyGao commented Nov 8, 2016

I got different result in the same code like below

With a Symfony command A I create a process running at background asynchronously, and it work fine in Linux, and I got the new process and the Pid as the command output.

Symfony command A

$command = 'php /somePath/app/console someCommand:processA';
$process = new Process($command);
$process->start();

$output->writeln($process->getPid());

Symfony command processA

$number = 1;
while (true) {
    $number++;
    $output->writeln($number);
}

But I could not got the process in Mac OS X, except I keep the Symfony command A live. Is there something wrong with the code or something different between Linux and Mac?

Linux: Ubuntu 15.10, PHP 5.6.11, Symfony 3.1.6
Mac OS: 10.11.6, PHP 5.5.38, Symfony 2.8.12

@jakzal
Copy link
Contributor
jakzal commented Nov 10, 2016

The goal of this component is to provide consistent process management across popular operating systems.

What happens on OS X exactly? I'm not sure what you mean by " I could not got the process in Mac OS X". Is the PID not returned, or no output shown from the process?

By the way, if you run symfony commands you need to be aware of: http://symfony.com/doc/current/components/process.html#process-pid

@TonyGao
Copy link
Author
TonyGao commented Nov 11, 2016

@jakzal Exactly in OS X, $process->start() just like crash, Nothing happen and there's no any php process in the process moniter. For instance by what I'm doing now

$process = new Process("exec afplay $pathToMusic");
$process->setTimeout(null);
$process->run();
$output->writeln('Music End baby :D');

afplay is a application to play music file in console, everything works well above, even without exec. Music show is going on, at the end I can see the ending words. But if I change run() method to start(), I just see "Music End baby :D" but without enjoying music anymore :(

In Linux start() method means keep working like a daemon, but I find there is no same effect in OS X . Any idea?

@jakzal
Copy link
Contributor
jakzal commented Nov 11, 2016

This is an expected behaviour.

Process you started with start() will die as soon as the parent process finishes. It will be stopped from the process'es destructor. Otherwise it would be terminated by the operating system. When using start() you need to use either wait() or isProcessRunning() to make sure you're not finishing the parent process before the child finishes.

Not sure why the linux process doesn't terminate in your case.

@stof
Copy link
Member
stof commented Nov 11, 2016

@jakzal this is because on Linux, killing a process does not kill its child processes. So only the sh wrapper gets killed, and not the actual command on Linux.

@tristanbes
Copy link
Contributor
tristanbes commented Nov 14, 2016

@jakzal wait, what ? According to you, we can't use the start method to say "ok launch this heavy task (eg: symfony command) and forget about it ?" What's the point of running an asynchronous process if the subprocess is killed when the parent is kiled (basically when you return a response for example ?)

How to achieve the fire and forget thing with the Process component so ? running it async and having to do isProcessRunning() kind of kill the benefit of the async feature :(

@stof
Copy link
Member
stof commented Nov 14, 2016

running an asynchronous process is not the same than running a processing surviving yourselves.
the goal of an asynchronous process is to be able to do other thing in your master process before dealing with the output of the subprocess (a typical case being to launch several subprocesses in parallel)

@TonyGao
Copy link
Author
TonyGao commented Nov 15, 2016

@stof got it, but I even use it as a feature in Linux, because I found it is really similar to a process of fork. I'm not sure if I can use $process = new Process("$consoleCommand &"); to make the process work in the background itself ? Is that suggested? Or something other solution like pcntl?

@nicolas-grekas
Copy link
Member
A873

This is unsupported on Symfony Process because the behavior of the OSes is different. There is no way I'm aware about to abstract these differences unfortunately. It doesn't mean you can't achieve it on your setup, it just mean nobody wrote such portable code for Symfony (and I doubt PHP provides the required primitives).
For this reason, running a processing surviving yourselves is a won't fix for me unfortunately.

@jakzal
Copy link
Contributor
jakzal commented Nov 22, 2016

As a result of #20513 a docs issue was raised to clarify this behaviour in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0