Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

symfony - What is the difference between using a Process and Console Application?

What would be the difference between running a Symfony console command programatically using:

1-

$command = $this->console.'swiftmailer:spool:send > output.log 2> out.log &';
$process = new SymfonyComponentProcess($command);
$process->run();

2-

$application = new SymfonyBundleFrameworkBundleConsoleApplication($kernel);
$application->setAutoExit(false);
        
$payload = ['command' => 'swiftmailer:spool:send'];

$input = new SymfonyComponentConsoleInputArrayInput($payload);

$output = new SymfonyComponentConsoleOutputBufferedOutput();
$application->run($input, $output);

I know in terms of handling the results is different but apart from that is there any other technological difference?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Process Component is using the proc_open function under the hood, using your operating system, in order to open file pointers for input/output and the proc_close to close a process and return the exit code of the process.

While The Console Component executes your console command without interacting with your operating system, but executes it programmatically within your application. Basically, it calls the execute function of your command.

In case you would like to run a Symfony console command, I would suggest to use The Console Component to avoid an operating system overhead, it allows you to pass any parameters you need and get output as well. In case you need to run an external command, the Process Component would be the right choice.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...