高流量数据库读/写错误PHP Laravel Aurora

时间:2015-11-12 23:30:05

标签: php mysql laravel amazon-rds amazon-rds-aurora

所以我们有一个laravel 5 php应用程序,每分钟1500-2000次读/写AWS Aurora数据库。它正在进行简单的选择,然后更新列中的值。

但是,我们在尝试不时更新值时会遇到一些错误。 (1/500会出错)

[2015-11-13 09:15:00] live.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function update() on null

这是我们的代码

// Get the first free token sorted by the biggest ID to the smallest.
$token = TokenModel::where('expire_at', '>', Carbon::now())
            ->where('status', 'Free')
            ->orderBy('id', 'DESC')
            ->lockForUpdate()
            ->first();

// Update the status of the token.
$token->update(['status' => 'Used']);

我们已尝试删除/添加lockForUpdate(),但这并不能解决问题。

以前有没有人遇到过这个问题?

更新

    $token = null;

    while ($token == null) {
        // Get the first free token sorted by the biggest ID to the smallest.
        $token = TokenModel::where('expire_at', '>', Carbon::now())
            ->where('status', 'Free')
            ->orderBy('id', 'DESC')
            ->lockForUpdate()
            ->first();
    }

0 个答案:

没有答案