roots / bedrock

WordPress boilerplate with Composer, easier configuration, and an improved folder structure
https://roots.io/bedrock/
MIT License
6.15k stars 1.16k forks source link

💥 use `Dotenv::createImmutable()` #714

Closed QWp6t closed 5 months ago

QWp6t commented 5 months ago

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 https://github.com/vlucas/phpdotenv/issues/248#issuecomment-450903446

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