-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
Is this problem when using putenv/getenv function? #238
Comments
This happens because Apache on Windows executes all php-requests within the same process, and the first request sets the variables and the second reads them. Dotenv will not overwrite existing variables, that is why the second request don't get all of the second sites .env stuff. This is a well-known issue and you will have other issues with your setup too, like building localized sites that calls setlocale() which also is process-wide. Regarding Laravel, you are supposed to run Related: #76 (Changing process environment unsafe on multithreaded servers) |
Thanks, yeh. This is a known issue, with known solutions, the solutions being, don't read the env variables directly, load them once into config. |
The current version of phpdotenv is robust and thread-safe. The following example will work in a multithreaded environment. This avoids using the adapter that would have called <?php
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Dotenv;
$factory = new DotenvFactory([new EnvConstAdapter(), new ServerConstAdapter()]);
Dotenv::create($path, null, $factory)->load(); |
(sorry for my bad english)
I made a simple test. I have 2 sites in a same Apache server (using virtual host)
With XAMPP stack, apache 2.4, I setup virtual host for 2 folders: test1.com and test2.com
So, when I call putenv('xxx=1') in one site. I can get that value in other site (over curl request).
I think this is a problem in some frameworks using dotenv to store .env config such as Laravel.
When I setup 2 Laravel projects (each project have separate folder, and separate .env file), one of them is WEB and other is API, WEB will call API to get data (using curl). Many keys in 2 .env files are the same. So, API will ignore keys was existed because WEB was load that keys => API will get wrong config (these configs are of WEB, not API)
Thanks
The text was updated successfully, but these errors were encountered: