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
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
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:
h/t https://github.com/vlucas/phpdotenv/issues/248#issuecomment-450903446
The rest of the PHP community has largely moved away from
putenv()
andgetenv()
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.