dongmisa4779 2016-10-06 13:11
浏览 41

Laravel多个并行请求似乎导致使用错误的连接

I'm having a Laravel 5.2 single page app that after rendering in the DOM will fetch some settings via AJAX calls. It is very possible that many ajax calls are done simultaneously.

Sometimes I will receive a 500 error because the table users cannot be found (which does exist). If I extract the query I can see that the used query language is sqlite while my database settings state that it should be sqlsrv. So it seems Laravel is using sqlite as database connection.

Does anyone has any idea on why this happens and what I can do to prevent it?

The database config is:

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],
    'acti' => [
        'driver' => env('DB_ACTI_DRIVER', 'sqlite'),
        'host' => env('DB_ACTI_HOST', null),
        'database' => env('DB_ACTI_DATABASE', ':memory:'),
        'username' => env('DB_ACTI_USERNAME', null),
        'password' => env('DB_ACTI_PASSWORD', null),
        'charset' => env('DB_ACTI_CHARSET', 'utf8'),
        'prefix' => env('DB_ACTI_PREFIX', ''),
        'strict' => false,
        'engine' => null,
    ],
    'aspect' => [
        'driver' => env('DB_ASPECT_DRIVER', 'sqlite'),
        'host' => env('DB_ASPECT_HOST', null),
        'database' => env('DB_ASPECT_DATABASE', ':memory:'),
        'username' => env('DB_ASPECT_USERNAME', null),
        'password' => env('DB_ASPECT_PASSWORD', null),
        'charset' => env('DB_ASPECT_CHARSET', 'utf8'),
        'prefix' => env('DB_ASPECT_PREFIX', ''),
        'strict' => false,
        'engine' => null,
    ],
    'navision' => [
        'driver' => env('DB_NAVISION_DRIVER', 'sqlite'),
        'host' => env('DB_NAVISION_HOST', null),
        'database' => env('DB_NAVISION_DATABASE', ':memory:'),
        'username' => env('DB_NAVISION_USERNAME', null),
        'password' => env('DB_NAVISION_PASSWORD', null),
        'charset' => env('DB_NAVISION_CHARSET', 'utf8'),
        'prefix' => env('DB_NAVISION_PREFIX', ''),
        'strict' => false,
        'engine' => null,
    ]
]

The ajax code is as follows:

        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: laroute.route('acti.preference.get', {
                pluginName: this.plugin.name,
                name: this.name
            }),
            success: $.proxy(function (data) {
                this.updateFromApi(data.value);
                if (data.value === undefined) {
                    this.saveToApi();
                }
            }, this),
            error: function () {
                console.log('receive error', arguments);
            }
        })

The standard connection is 'acti' and the .env holds the correct information.

After some testing I can confirm that the env method does not always return the correct information. I can see that sometimes the default value (which is sqlite) is returned in stead of the actual data in the .env file.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题