Laravel 5.0,env()在并发请求期间返回null [英] Laravel 5.0, env() returns null during concurrent requests

查看:92
本文介绍了Laravel 5.0,env()在并发请求期间返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我尝试使用env('setting')\Config::get('setting')获取配置变量时,有时它返回null.

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]);
    }
});

然后,我使用了Apache基准测试.结果是这样的:

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

  • 一次只调用一个请求(ab -n 100 -c 1 http://localhost/test)没问题,日志文件中没有记录
  • 通过10个并发请求进行调用(ab -n 100 -c 10 http://localhost/test),我得到大约20行,如下所示:[2015-06-22 14:19:48] local.WARNING: test [null]
  • Calling only one request at a time (ab -n 100 -c 1 http://localhost/test) there were no problem, no records in the log file
  • Calling with 10 concurrent requests (ab -n 100 -c 10 http://localhost/test) I got about 20 lines like this: [2015-06-22 14:19:48] local.WARNING: test [null]

有人知道,这可能是什么问题?我的配置或php设置中缺少某些内容吗?

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

推荐答案

这是dotenv程序包中的一个已知错误-参见此处的讨论 https://github.com/laravel/framework/issues/8191

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

这篇关于Laravel 5.0,env()在并发请求期间返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆