From this I see init constructor of Dotenv and use load() function, So, all keys of .env file will set to immutable.
Please check this from Loader of Dotenv. When environment variable is immutable and it was existed we will ignore it.
When setup multiple Laravel sites in a same Apache server. In same request, they can read env value of each others (same request mean we access to A site from browser, A site make a http request to B site (using curl) and A site display response of B site to web browser).
I think the main reason related to putenv of Dotenv Please check this
Php putenv ref
I can bypass this issue by changing here, from load() function to overload() function to make variable become mutable. But I don't think this is safe solution.
Anybody meet the same situation? Please give me an advise!
Thanks
You should be running with a cached configuration to prevent these kinds of issues. Environment variables defined by php and not Apache (or FPM) can have issues like this.
There are two things to make sure of here:
env() in your config/*.php files. If you need to use it elsewhere add a property to the appropriate config file (or create a new one to put it in if necessary) and reference it with the config() function.php artisan config:cache to ensure that the env vars are cached. When you do this Laravel will not read from the .env or config/*.php files, and instead used a cached config file. Because of this, referencing those environment variables with env() will return null. You should run the php artisan config:cache command any time you deploy code or make changes to your environment variables.Please continue the discussion on the forums. The repo is for bugs in the core only.
Most helpful comment
You should be running with a cached configuration to prevent these kinds of issues. Environment variables defined by php and not Apache (or FPM) can have issues like this.
There are two things to make sure of here:
env()in yourconfig/*.phpfiles. If you need to use it elsewhere add a property to the appropriate config file (or create a new one to put it in if necessary) and reference it with theconfig()function.php artisan config:cacheto ensure that the env vars are cached. When you do this Laravel will not read from the.envorconfig/*.phpfiles, and instead used a cached config file. Because of this, referencing those environment variables withenv()will returnnull. You should run thephp artisan config:cachecommand any time you deploy code or make changes to your environment variables.