Laravel 5.0, env () returns null during concurrent requests
The problem is that when I try to get the config variable using env('setting')
or \Config::get('setting')
, sometimes it returns null.
For testing reasons, I created a simple route:
Route::get('/test', function () {
$env = env('SETTING');
if (!$env) {
\Log::warning('test', [$env]);
}
});
Then I used apache test. And the results were like this:
- Calling only one query at a time (
ab -n 100 -c 1 http://localhost/test
) had no problem, no log file entries - Call with 10 parallel queries (
ab -n 100 -c 10 http://localhost/test
) I got about 20 lines:[2015-06-22 14:19:48] local.WARNING: test [null]
Does anyone know what the problem is? Is there something missing in my configuration or php settings?
+3
Dmitry Gryanko
source
to share
2 answers
This is a bug in the dotenv package - see discussion here https://github.com/laravel/framework/issues/8191
0
Moin ahmed
source
to share
It happens to me too. My workaround is in yours config/app.php
, you have to add this:
'setting' => env('SETTING'),
Then, when you want to get the settings configuration, you should do this:
$env = config('app.setting');
0
aceraven777
source
to share