简体   繁体   中英

php artisan queue:work not working with mongodb and laravel 5.2

I have installed laravel 5.2.0 and https://github.com/jenssegers/laravel-mongodb , and want to send emails via queue. I've created jobs table successfully but when running php artisan queue:work command it is throwing following error -

PHP Fatal error: Call to a member function beginTransaction() on null in /var/www/html/admin/setupl/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 576

I've checked database connection , here is my complete logs in command line - 在此处输入图片说明

I've spent many hours to resolve it but still not working.Any help would be really appreciated , thanks much.

Edit - As suggested "MongoDB do not have transactions, so when Laravel tries to begin one an exception is throwed" here https://github.com/jenssegers/laravel-mongodb/pull/871 , I have commented codes in beginTransaction and commit() and return null, now error has gone but still command not working.

public function commit()
{
    return null;
}

And

public function beginTransaction()
{
    return null;
}

It's better if you just use Redis as cache for Laravel . It's much more appropriate for queues and has native support. I use Redis as worker queue and Mongo as db

We ran into the same problem back in Laravel 5.1 and despite patching the laravel-mongodb queue implementation up with the proper _id Mongo identifiers, we found the query builder syntax doesn't allow for proper atomicity at the database level. We ended up writing our own queue driver that implements document-level locking. That way we can guarantee each job is only run once if there are multiple workers.

You can find versions of our queue driver that work for Laravel 5.1+ here: https://github.com/chefsplate/laravel-mongodb-queue

The main concern we had for using REDIS as a queue is that unless you can reliably flush to disk, since all the jobs are stored in memory, there is a possibility that you may lose jobs in the event REDIS goes down. And if you are writing REDIS to disk frequently (which comes with its own set of concerns), you may be better off using a persistent store like MongoDB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM