-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Added a short section about "Setting Environment Variables for Processes" #10983
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -128,6 +128,28 @@ environment variables using the second argument of the ``run()``, | |||||
// On both Unix-like and Windows | ||||||
$process->run(null, ['MESSAGE' => 'Something to output']); | ||||||
|
||||||
Setting Environment Variables for Processes | ||||||
------------------------------------------- | ||||||
|
||||||
The constructor of the :class:`Symfony\\Component\\Process\\Process` class and | ||||||
all its methods related to executing processes (``run()``, ``mustRun()``, | ||||||
``start()``, etc.) allow passing an array of environment variables to set before | ||||||
javiereguiluz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
``start()``, etc.) allow passing an array of environment variables to set before | |
``start()``, etc.), allow passing an array of environment variables to set before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need both lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're trying to display multiple different ways to set up env vars. Thats's why we have several lines.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this is only noise
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These environment variables and the already existing environment variables bound to the current process are inherited by child processes. You can hide an environment variable from child processes by setting it to false
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need some help trying to understand this in practice. Imagine this command:
$process = new Process(['foo'], null, ['APP_ENV' => 'test']);
foo
command is run with APP_ENV=test
and if foo
starts new processes or runs commands, they will use APP_ENV=test
too. OK.
But here we are saying, if you want to prevent that, set the env var to false
:
$process = new Process(['foo'], null, ['APP_ENV' => false]);
OK, so child processes now don't use APP_ENV=test
... but the main foo
command doesn't either, right?
Question: how can I define an env var for a command ... and prevent defining it for its child processes? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A running Process
instance is a child process. We don't make a difference between a child process and its sub-children. That's not our responsibility at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I understand. Thanks!
javiereguiluz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this is only noise
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you keep this, you should add this:
'SYMFONY_DOTENV_VARS' => false | |
'SYMFONY_DOTENV_VARS' => false, |
Uh oh!
There was an error while loading. Please reload this page.