You do not have to cache the config in Lumen for your issue. There is a different solution for dotenv
issue for WAMP (probably other environments suffer too, see the first link below).
You have to give different names to .env
variables that share the same name now. Then you have to change the variables names in your respective config/<configname>.php
's files. The example follows.
Example
Assume you have 2 apps under the same server, different virtual hosts (under WAMP). One app is Lumen API A, another is Lumen API B.
The issue comes from the fact that the caller (API A) .env
variables are not overwritten by the callee (API B respectively) .env
variables when HTTP request arrives to callee. But this is only when these varibles have the same names.
I.e. your caller (API A) .env
variables being read in memory
DB_DATABASE=<api_a_1>
DB_USERNAME=<api_a_2>
will not be replaced by the callee's ones (API B) side despite the fact the callee callee .env
file has them like this:
DB_DATABASE=<api_b_1>
DB_USERNAME=<api_b_2>
The solution is to name them differently and put the new names into config/database.php
. Like this:
API A:
# .env file
API_A_DB_DATABASE=<api_a_1>
API_A_DB_USERNAME=<api_a_2>
// config/database.php file
...
// ... other keys
'connections'=> [
// ... other keys
'mysql'=> [
'database' => env('API_A_DB_DATABASE', 'forge'),
'username' => env('API_A_DB_USERNAME', 'forge'),
]
]
API B:
You can keep the default variable names or assign them a prefix API_B_
if you API B can be a caller to other Lumen APIs in this server too.
Now you do not need to cache config on your API A caller side as your API B callee side variables will be always read into memory due to them having the different names.
Details
I would advise reading this explanation on laravel/framework
repo issues list. If the caller is Laravel app you can fix the same issue by php artisan config:cache
, see details on this SO post.