rethinkdb PHP-RQL 变化 [英] rethinkdb PHP-RQL changes

查看:36
本文介绍了rethinkdb PHP-RQL 变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP-RQL 库来处理 RethinkDB,我需要在插入新数据时进行更改.但我收到 PHP 致命错误:未捕获的 RqlDriverError:选项必须是一个数组.

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.

在 api 文档中它说:

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.

推荐答案

PHP-RQL 目前是完全同步的,所以你不能给它回调.相反,您会得到一个可以迭代的游标:

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);
})

你用什么来实现并发?您在使用任何异步框架 (React PHP) 或多线程或类似的东西吗?

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

目前还没有与 PHP-RQL 原生集成到 React 中,但如果您正在运行启用线程的 PHP 版本,您可以生成一个线程,在线程内打开一个单独的连接并使用来自的同步游标接口在里面.

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.

这篇关于rethinkdb PHP-RQL 变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆