3

I'm looking for how to perform the equivalent Laravel command with Lumen

php artisan config:cache

This doesn't seem to be available as a Lumen artisan command?

UPDATE I have found this related question but this only says that it doesn't exist.

I am currently having trouble with lumen and the DotEnv library reading the .env file for rapid requests. This causes the .env file not to be read, and lumen to use its default settings which are incorrect for my app.

I'm hesitant to copy the config:cache function from laravel to my lumen app. This doesn't seem right? What is the lumen way to handle this?

UPDATE 2 After digging around in Lumen and Illuminate code, it seems a way to do this more reliably is to define files (e.g. config/database.php) that have the desired values, and not use the .env file?

Turtle1363
  • 312
  • 3
  • 16
  • Hi, did you get some updated for your problem? Now, I seem that I had the same problem, did you create config/database.php file? Regards. – hizmarck Aug 26 '19 at 04:32
  • Yes, just created the config/database.php file – Turtle1363 Aug 26 '19 at 12:26
  • I've added $app->configure('database'); in my bootstrap/app.php and the file config/database.php and didn't work, I've omitted something? Thanks for your support. – hizmarck Aug 26 '19 at 12:46
  • I didn't need $app->configure('database'). Basically, I just did not have an .env file. Instead, I just hardcoded the production values in the config/database.php as the default option for the env() calls. Luckily for my simple application I was using a local sqlite, so I did not need to store a database password. – Turtle1363 Aug 26 '19 at 15:09

1 Answers1

0

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.

Valentine Shi
  • 6,604
  • 4
  • 46
  • 46