0

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.

  • The example in the API docs is just wrong. Sorry for the confusion. I opened https://github.com/danielmewes/php-rql/issues/108 about that. See below for how it currently works in PHP-RQL. – Daniel Mewes Oct 07 '15 at 02:47

1 Answers1

4

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.

Daniel Mewes
  • 1,876
  • 14
  • 16