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

💥 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
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
jazzsequence added a commit to pantheon-systems/wordpress-composer-managed that referenced this pull request Jun 27, 2024
jazzsequence added a commit to pantheon-systems/wordpress-composer-managed that referenced this pull request Jun 27, 2024
* use `Dotenv::createImmutable()`
see roots/bedrock#714

* Remove post install .env copy
see roots/bedrock#595

* inline comments end in full stops
jazzsequence added a commit to pantheon-systems/wordpress-composer-managed that referenced this pull request Jul 31, 2024
* use `Dotenv::createImmutable()`
see roots/bedrock#714

* Remove post install .env copy
see roots/bedrock#595

* inline comments end in full stops
jazzsequence added a commit to pantheon-systems/wordpress-composer-managed that referenced this pull request Aug 1, 2024
* use `Dotenv::createImmutable()`
see roots/bedrock#714

* Remove post install .env copy
see roots/bedrock#595

* inline comments end in full stops
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