reactphp / reactphp

Event-driven, non-blocking I/O with PHP.

Home Page:https://reactphp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use PDO with Reactphp ?

raheelkhan opened this issue · comments

Is there any way we can use PDO with Reactphp ? Or is there any guideline how we can make our custom classes works asynchronously with Reactphp ?

Thank you for this excellent question! Unfortunately, PDO itself does not support non-blocking operation and as such should not be used in a truly async program.

As an alternative, a number of database drivers for MySQL, Postgres, Redis etc. are already available for ReactPHP, see also https://github.com/reactphp/react/wiki/Users#databases.

I hope this helps! 👍

Looks like the examples are pure PHP implementations of those databases and it looks like MongoDB implementation is not there yet. Does that mean any drive that needs to be made work with ReactPHP shall be written in pure PHP?

There's already an experimental project for MongoDB connection: https://github.com/jmikola/react-mongodb.
I don't think you'd find non pure PHP implementations of such things. The best guess I could have is to explore the DB functions instead of the PDO, maybe there you could find a socket parameter or similar that you could exploit. Again: not sure, is just a guess.

@nawarian What do you exactly mean by the DB functions? I probably can look into MongoDB ASYNC for node.js and get an idea from there.

The driver-specific db functions, like mysqli_connect... Again: is just a guess, I'm not quite sure if it is possible and unfortunately have no time to do proper research :/