ReactPHP & MongoDB - Possible Use Scenarios
After working with commercetools (that uses MongoDB internally, but it shows in their APIs) and presentation at SyliusCon I wanted to give MongoDB another try. Since I do like working with ReactPHP for some things, and I had the opportunity now to prototype a new app, I looked through ways of properly using MongoDB and ReactPHP. As You may have already figured out ReactPHP is not a fully multithreaded environment. It is still one single thread used for multiple and acts like multithreaded only by leveraging non-blocking I/O (and Fibers in PHP 8.2 does not change that, it is just another interface to hide that fact). Unfortunately, MongoDB Driver for PHP is relying on an extension that internally uses libmongoc for all I/O operations—this means that it cannot be easily used with ReactPHP (and based on discussions of the MongoDB PHP Driver creators on their issue tracker there is no plan to change it since there is no plan in PHP to provide a common user-land way to leverage event loops—there is one in HHVM, so maybe something cool will emerge in a driver for HHVM, but I am not following what is going on in there)