Laravel 5.3 queue:work artisan 命令出现 null 错误时获取 beginTransaction()

Laravel 5.3 Getting beginTransaction() on null error for queue:work artisan command

当我尝试 运行 php artisan queue:work 命令时,出现此错误:

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function beginTransaction() on null

我已经检查了互联网上关于此错误的几乎所有可用帮助,但我没有找到任何解决方案。

我不确定这是否与我正在使用的这个软件包有关。

https://github.com/jenssegers/laravel-mongodb

我猜可能是因为其他人也遇到了这个错误,但不幸的是没有任何回复。

https://github.com/jenssegers/laravel-mongodb/issues/964

日志中的详细错误:

[2016-11-12 20:18:45] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function beginTransaction() on null' in C:\wamp\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:611
Stack trace:
#0 {main}  

如有任何帮助,我们将不胜感激。

提前致谢。

谢谢,

Parth vora

我找到问题了。

我没有遵循包裹的队列配置。

https://github.com/jenssegers/laravel-mongodb#queues

只要按照正确的说明进行操作,效果就会很好。

我也遇到了 DB::beginTransaction() 方法的问题。以下片段解决了我的问题

$session = DB::getMongoClient()->startSession();
$session->startTransaction();
try {
    // Perform actions.
    $session->commitTransaction();
} catch(Exception $e) {
    $session->abortTransaction();
}

感谢


顺便说一句,我正在使用 MongoDB 版本 4.0.3 并在 Laravel 版本 5.7 和 5.8

上进行了测试

我研究后发现这与 MySQL/MariaDB 是 "killed to free memory" 有关。因此,我在 cent os rhel 7 上使用 sudo shutdown -r 重新启动了服务器,并使用 sudo systemctl restart mariadb 启动了 mysql/mariadb。