Dmitry Gryanko
Dmitry Gryanko

Reputation: 153

Laravel 5.0, env() returns null during concurrent requests

The problem is that when I try to get a config variable using env('setting') or \Config::get('setting'), sometimes it returns null.

For the testing reason I created a simple route:

Route::get('/test', function () {
    $env = env('SETTING');
    if (!$env) {
        \Log::warning('test', [$env]);
    }
});

Then I used apache benchmark. And the results were like this:

Does anybody know, what can be the problem? Is there something missing in my configuration or in php settings?

Upvotes: 5

Views: 2721

Answers (2)

Moin Ahmed
Moin Ahmed

Reputation: 146

This is a know bug in dotenv package - see the discussion here https://github.com/laravel/framework/issues/8191

Upvotes: 1

aceraven777
aceraven777

Reputation: 4556

This happen to me as well. My workaround is in your config/app.php you have to add this:

'setting' => env('SETTING'),

Then when you want to get the setting config you have to do this:

$env = config('app.setting');

Upvotes: 0

Related Questions