Skip to content
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

[5.8] Added PutenvAdapter to env() helper #27814

Closed
wants to merge 1 commit into from
Closed

[5.8] Added PutenvAdapter to env() helper #27814

wants to merge 1 commit into from

Conversation

kieranbrown
Copy link
Contributor

@kieranbrown kieranbrown commented Mar 7, 2019

Overview

This is related to an already reported issue: #27769.

The default behavior of PHP will not load environment variables into $_ENV and can only be retrieved using the getenv function.

; 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
variables_order = "GPCS"

There are issues currently with not being able to retrieve physical server environment variables.

Proposed Solution

Include the PutenvAdapter to keep the same behavior prior to 5.8.

@GrahamCampbell
Copy link
Member

This adapter was intentionally removed to stop variables from leaking into Laravel apps due to the non-thread-safety of getenv and putenv.

@GrahamCampbell
Copy link
Member

You can still have this old behaviour in your app if you need it, by just extending Laravel's bootstrapper in your own app, and changing the one used in your http and console kernels.

@kieranbrown
Copy link
Contributor Author

@GrahamCampbell Thanks for the reply, how would this work in Lumen? We set our environment variables in Docker so there is no .env file, thus no Dotenv bootstrap process. The only solution I can think of to make these variables accessible is to change config to load them into $_ENV or $_SERVER.

Would you suggest doing that, or adding a .env file and using the "LoadEnvironmentVariables" bootstrapper in Lumen?

I'm confused how the latter would work in a production environment because Lumen can't cache these environment variables into config during the build process.

Appreciate your help.

@kieranbrown
Copy link
Contributor Author

For anybody else wondering, this got merged in eventually. See #27958

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.

2 participants