Support async queries with loop/promise implementations

Description

There are very popular async PHP frameworks like ReactPHP or Amphp. They are all based on loops and support backends like libevent, libuv. This allows to make use of very efficient kernel implementations (epoll, kqueue) to poll for events.

Unfortunately with the php cassandra driver this is not possible. You offer an async interface but this has to be polled manually future by future and there isn't even a method to cheaply check if the future is set (even though CPP CassFuture offers that).

One way to attach the php-driver to a epoll based loop is to use a socket as a notification channel between the PHP driver and a loop. The CPP driver supports callbacks. Such a callback could simply write into a defined FD that a future is set. This could be achieved by assigning a incremental future id to each future and write this id to a socket. Then this socket can be polled super-cheap and the appropriate pending future can then be fetched without blocking.

A possible low level way of implementing that:

  • Future interface is extended by:

  • getId()

  • isSet() <= still allows faster manual polling

  • Execute options have a new optional parameter "watcher" which must be a PHP resource from which a file descriptor can be used in CPP to write the future id in the callback

  • A future callback is set only if the watcher resource is set

Of course there could be higher level implementations but this would work with any framework on a low level. So e.g. a react or amphp adapter for the CS driver could simply be written that wraps a CS future into a promise.

Environment

None

Pull Requests

None

Activity

Show:

Michael Penick October 24, 2017 at 4:16 PM

This would be an awesome feature, but don't currently have any plans to add this. A pull request would be welcome.

Details

Assignee

Reporter

Priority

Created October 20, 2017 at 7:54 PM
Updated October 24, 2017 at 4:16 PM

Flag notifications