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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃挜 use Dotenv::createImmutable() #714

Merged
merged 1 commit into from Apr 7, 2024
Merged

馃挜 use Dotenv::createImmutable() #714

merged 1 commit into from Apr 7, 2024

Conversation

QWp6t
Copy link
Sponsor Member

@QWp6t QWp6t commented Apr 6, 2024

This has been brought up a few times internally and in the comments in this repo.

Here's an example scenario in a multithreaded environment:

Putenv and Getenv are not thread-safe. This is probably the cause of your issue.

What happens is the following:
1st request: variables are not there -> load
2nd request: variables are there -> do not load
1st request: ends, cleans up variables
2nd request: use variable -> does not exist anymore, cleaned up by 1st request

h/t vlucas/phpdotenv#248 (comment)

The rest of the PHP community has largely moved away from putenv() and getenv() due to this limitation, and it's the reason why vlucas/phpdotenv moved away from it as a default and advises against it in their readme.

Using getenv() and putenv() is strongly discouraged due to the fact that these functions are not thread safe

@QWp6t QWp6t requested a review from swalkinshaw April 6, 2024 23:58
@QWp6t QWp6t merged commit 3eccb5b into master Apr 7, 2024
8 checks passed
@QWp6t QWp6t deleted the thread-safe-dotenv branch April 7, 2024 03:42
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.

None yet

2 participants