1

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

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

[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();
    }
4

0 回答 0