rethinkdb PHP-RQL changes

2019-09-08 08:09发布

问题:

I'm using PHP-RQL library to work with RethinkDB, i need to get changes when new data inserted. but i'm getting PHP Fatal error: Uncaught RqlDriverError: Options must be an array.

in api documentation its says:

table->changes(array('squash' => true, 'include_states' => false)) → stream
singleSelection->changes(array('squash' => true, 'include_states' => false)) → stream
Return an infinite stream of objects representing changes to a query.

Example: Subscribe to the changes on a table.

r\table('games')->changes()->run($conn, function($err, $cursor) {
    $cursor->each($console->$log)
})

How to subscribe to the changes on a table? This example is doesn't work.

回答1:

PHP-RQL is fully synchronous at the moment, so you cannot give it a callback. Instead you get a cursor that you can iterate:

$cursor = r\table('games')->changes()->run($conn);
foreach ($update in $cursor) {
    printr($update);
})

What are you using for concurrency? Are you using any async framework (React PHP) or multi-threading or anything like that?

There's no native integration into React with PHP-RQL at the moment, though if you're running a thread-enabled version of PHP you can spawn a thread, open a separate connection inside the thread and use the synchronous cursor interface from within there.



标签: php rethinkdb