-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: use getenv() instead of $_SERVER in detectEnvironment() #6257
Conversation
Use getenv instead of $_SESSION in detectEnvironment
Can't reproduce. I checked
|
If you have CodeIgniter4/system/Config/DotEnv.php Lines 89 to 102 in d75e426
|
Yes @kenjis, that should be the case in the presence of a .env file, like when you COPY the file in the Dockerfile. But it's not the case when loading environment variables in other scenarios, like when using |
Okay, I got your situation. You don't use By the way, why do we use |
env() is slower than getenv().
|
It may be slower because it checks all available places ( |
class Home extends BaseController
{
public function index()
{
return getenv('CI_ENVIRONMENT');
}
}
$ CI_ENVIRONMENT=development php spark serve
I see "development". |
It seems there are three options:
|
Oops, I reviewed before I saw this discussion. I'm fine with .07s performance hit if |
|
It seems Apache
If so, the following setting does not set
Concluseion: using |
@fcosrno Are you available to confirm that If we don't hear back today I will merge #6257 (comment) and we can proceed with final review. |
Yes, I can confirm env() fixes the issue. |
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.
Okay, all green!
@fcosrno Thank you for confirmation.
💪 |
Description
Update CodeIgniter.php to use getenv() instead of $_SERVER in detectEnvironment. The outcome of environment variables loading in either $_SERVER or $_ENV depends on the operating system and web server. For instance, in a Docker environment the
.env
file loads variables in $_ENV, resulting in detectEnvironment() not seeing CI_ENVIRONMENT when defined. Using getenv() instead of directly reading from $_SERVER solves this issue.Fixes #6313
Checklist: