amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘
https://amphp.org/amp
MIT License
4.24k stars 257 forks source link

MongoDB Support #138

Open cordovapolymer opened 7 years ago

cordovapolymer commented 7 years ago

Hi! Thanks for a great effort making php async! Is mongodb supported? If so can you give an example of its usage?

kelunik commented 7 years ago

I'm not aware of any implementation on Amp directly, but there's https://github.com/jmikola/react-mongodb which is based on ReactPHP and thus fully compatible with Amp v2. That package is marked as experimental, but maybe it helps.

cordovapolymer commented 7 years ago

@kelunik , unfortunately it doesn't work with php7 and new mongodb php driver.

bwoebi commented 7 years ago

Hmm. Well, judging by the react-mongodb library, it should be pretty easy to write your own driver for this using amp.

If there is interest, I also may prototype such a basic library in a couple of hours.

cordovapolymer commented 7 years ago

@bwoebi , please note that react-mongodb is based on a legacy php mongo extension for BSON processing which is not supported in PHP7, new mongodb extension is much sleeker, it provides BSON serialization and some low level features, but it lacks Asynchronous Queries support, there's a PHP library that is based on the new extension which implements all mongodb features.

What do you think about prototyping a basic amp driver which would be compatible with the mongo php library, so it could be used together in amp based apps?

jmikola commented 7 years ago

https://github.com/jmikola/react-mongodb is really just a proof of concept for executing basic queries and commands asynchronously. It only depends on the legacy extension for BSON encoding and decoding, but that could be trivially changed to use the new extension's functions and classes. I would not expect the PHP library to be usable atop any async PHP driver.

That said, it lacks many of the essential features you'd need in a driver. TLS connections, authentication, server discovery and monitoring, and a usable API. An ideal API would probably be modeled after the Node.js driver or Motor (for Python).

As a side note, https://github.com/mongofill/mongofill implements the legacy driver's BSON API in pure PHP if you were looking to bootstrap a new async driver without any extension dependency.

kelunik commented 7 years ago

Closing this issue, the possible options have been mentioned. Another option is to build a driver based on amphp/parallel.

kelunik commented 6 years ago

Re-opening. Introduced the package request label for these kind of requests. I think amphp/amp is the best repository to collect these.