Skip to content

Commit 54751db

Browse files
committed
changed setOptions() and __destruct()
1 parent 859c68b commit 54751db

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static function fromShellCommandline(string $command, string $cwd = null,
197197

198198
public function __destruct()
199199
{
200-
if (!$this->options['create_new_console']) {
200+
if (!($this->options['detach'] ?? $this->options['create_new_console'])) {
201201
$this->stop(0);
202202
} else {
203203
$this->processPipes->close();
@@ -1228,24 +1228,24 @@ public function getStartTime(): float
12281228
* detach option can be used to run a process in the background
12291229
* using detach you can can finish execution before the process has finished working
12301230
* use setOptions(['detach' => true]) before using start
1231+
* on Win you need both detach => true, and create_new_console => true, to start a bacground process and exit your main script without waiting for the process to finish
12311232
* detach requires minimum PHP 7.4.4.
12321233
*/
12331234
public function setOptions(array $options)
12341235
{
1236+
if ($this->isRunning()) {
1237+
throw new RuntimeException('Setting options while the process is running is not possible.');
1238+
}
1239+
12351240
$defaultOptions = $this->options;
1236-
$existingWinOptions = ['blocking_pipes', 'create_process_group', 'detach'];
1241+
$existingOptions = ['blocking_pipes', 'create_process_group', 'detach', 'create_new_console'];
12371242

12381243
foreach ($options as $key => $value) {
1239-
if (!\in_array($key, $existingWinOptions)) {
1244+
if (!\in_array($key, $existingOptions)) {
12401245
$this->options = $defaultOptions;
12411246
throw new LogicException(sprintf('Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode('", "', $existingOptions)));
12421247
}
1243-
1244-
if ('detach' === $key) {
1245-
$this->options['create_new_console'] = $value;
1246-
} else {
1247-
$this->options[$key] = $value;
1248-
}
1248+
$this->options[$key] = $value;
12491249
}
12501250
}
12511251

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy