I have two Laravel 5.2 applications (lets call them A and B) on my local computer, both configured on two different virtual hosts on my local Apache 2.4 development server.
Both applications sometimes call each other through GuzzleHttp.
At some point, I wanted to use encryption, and I began to get "mac is invalid" exceptions from Laravel Encrypter.
When investigating the problem, I found that when application A calls application B, application B suddenly gets the encryption key (app.key) from application A! This causes encryption to fail because the values ββin application B are encrypted using the encryption key of application B.
During debugging, I discovered that the Dotenv library has some logic for preserving existing variables, if set. I found that both $ _ENV and $ _SERVER do not have missing variables, but getenv() has them!
I'm a bit confused because php putenv says:
An environment variable will exist only during the current request.
It seems that during the current request I run another request via GuzzleHttp, the variables set by Dotenv using putenv() suddenly become available in application B, which is requested using GuzzleHttp!
I understand that this will not be a problem on production servers, where the configuration cache will be used instead of Dotenv, and most likely both applications will work on different Apache servers, but this behavior violates my development process.
How to configure Laravel or GuzzleHttp or Apache or PHP to prevent putenv() from leaking from application A to application B?
php apache laravel guzzle
Justamartin
source share