-
Notifications
You must be signed in to change notification settings - Fork 11k
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
.env issue with PHP thread-safe #7354
Comments
Please open an issue on the phpdotenv repo. |
But it's not a phpdotenv issue! It's a PHP issue. However, I open an issue on Laravel because it can be solved in the way I explained. Why ignore my issue while I suggest a solution? |
There's nothing we can realistically do about it. |
Wait, what? If you've got a solution, then feel free to send a pull. That would be awesome! :) Issues aren't very helpful to us. |
@bioteck Have you noticed? You should choose where to post issues depending on whether you have solution. 👍 |
Change |
@crynobone I actually already privately discussed this via email, and it's clear that I was too hastily to dismiss this, but we're very much happy to receive pull requests to address this :) |
Code from vlucas/phpdotenv repository
If I load my local .env file with this method my code is worked. You need to specify this in boot function on laravel. You can create a middleware function with:
and after that you need to add the code to Or you can use the AppBefore middleware's
And you need to add middleware to
|
@fkomaralp Laravel automatically calls the load method for you when the framework boots. |
Let's not use / anymore as they are not thread safe. laravel/framework#7354
If anyone is interested this issues only started happening to us when we set |
I noticed a problem with functions putenv() and getenv() when PHP is thread-safe: if a URL is called before another is completed, its environment variables will be reset when the first script is finished. It's problematic with ajax requests, or simply if a user opens several links too quickly in new tabs (for example).
You can reproduce this bug by using WampServer, or any other server with PHP thread-safe, and creating two routes in "app/Http/routes.php":
Then call "test1", and while it's sleeping, call "test2".
"test1" will display "APP_ENV: local", but "test2" will display "APP_ENV: "
This problem occurred with getenv(), but $_ENV and $_SERVER are not affected. So it can be resolved by using Dotenv::findEnvironmentVariable(), which uses $_ENV in priority, instead of getenv() in helper env():
The call of Dotenv::makeMutable() is also needed in bootstrapper "DetectEnvironment.php":
The text was updated successfully, but these errors were encountered: