8000 [FWBundle] $_ENV fallback (needed for Panther) by dunglas · Pull Request #464 · symfony/recipes · GitHub
[go: up one dir, main page]

Skip to content

[FWBundle] $_ENV fallback (needed for Panther) #464

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 statemen 8000 t. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Sep 21, 2018
Merged

Conversation

dunglas
Copy link
Member
@dunglas dunglas commented Sep 20, 2018
Q A
License MIT

When the builtin PHP web server is used, env vars are only available in $_ENV, not in $_SERVER (see https://bugs.php.net/bug.php?id=67808).

This is especially annoying when testing an app with Panther because, by default, it automatically boots the app using the integrated PHP web server, consequently env vars defined in phpunit.xml aren't inherited, and the app executed using the dev env instead of the test one.

This PR fixes this problem.

Copy link
@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link
Contributor
@bocharsky-bw bocharsky-bw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes 👍

But we still need a way to be able to load websites in prod/test env when loading Symfony webserver in dev mode because, by default, the server is registered for dev mode only that makes sense, we should not register it for test/prod. See related #461 that may fix the issue I mentioned.

Copy link
Contributor
@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

@ghost ghost merged commit 334f189 into symfony:master Sep 21, 2018
ghost pushed a commit that referenced this pull request Sep 21, 2018
@albertboada
Copy link

Why not using getenv()?

@dunglas dunglas deleted the merge-env branch October 10, 2018 20:15
@dunglas
Copy link
Member Author
dunglas commented Oct 10, 2018

@albertboada because it's not thread safe.

@stof
Copy link
Member
stof commented Oct 11, 2018

Does DotEnv checks both $_SERVER and $_ENV for existing env variables too ?

@Pierstoval
Copy link
Contributor

@albertboada
Copy link
albertboada commented Oct 11, 2018

@albertboada because it's not thread safe.

Thanks @dunglas, I see.

However, we are experimenting a situation where 'APP_ENV' is neither set in $_SERVER nor in $_ENV, and the only way of bootstrapping correctly our Symfony 4 application in our production is falling back to getenv(). We are deploying on Amazon Elastic Container Service. Any particular reason why this can happen?

EDIT:
Ok, found it. Sorry for the de-rail. For all those in the same situation, it is all about PHP's variables_order directive. Ours is set to variables_order = "GPCS", so the $_ENV array is not populated. From php.ini:

; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers. You
; can still get access to the environment variables through getenv() should you
; need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order

One wonders, though. If the performance penalty is considerable, and it is not recommended in production environments, is it really sufficient to just check $_SERVER and $_ENV for bootstrapping Symfony?

Cheers!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0