rethinkdb PHP-RQL changes

痞子三分冷 提交于 2019-12-11 19:45:52

问题


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.



来源:https://stackoverflow.com/questions/32850344/rethinkdb-php-rql-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!