I trying to make a realtime stats bar. And I think of using the Long Polling concept.
我试图制作一个实时统计栏。我想到使用Long Polling概念。
But when a request is send to php. I need a way of testing if the stats are updated.
但是当一个请求被发送到php。我需要一种测试统计数据是否更新的方法。
Now I can just make a loop with a database query, and test it. But that just doesn't seem right to me :)
现在我可以用数据库查询创建一个循环,并测试它。但这对我来说似乎不对:)
Is there a more inexpensive method of testing the database for updates?
是否有更便宜的方法来测试数据库以进行更新?
1 个解决方案
#1
1
This will depend on how intensive the query for determining whether stats are updated is. If it's a simple (and fast) query, then that would be the best option. If it's an expensive query, change how the stats are updated so you either set a datestamp or have a DB trigger do it for you. No matter what, you're going to need some type of query to check for updates.
这将取决于确定统计信息是否更新的查询密集程度。如果它是一个简单(快速)的查询,那么这将是最好的选择。如果这是一个昂贵的查询,请更改统计信息的更新方式,以便您设置日期戳或让DB触发器为您执行此操作。无论如何,您将需要某种类型的查询来检查更新。
And you can't "push" from server to client either, so no matter what you'll need ajax polling so the client initiates the check....
并且你也不能从服务器“推送”到客户端,所以不管你需要什么样的ajax轮询,所以客户端启动检查....
#1
1
This will depend on how intensive the query for determining whether stats are updated is. If it's a simple (and fast) query, then that would be the best option. If it's an expensive query, change how the stats are updated so you either set a datestamp or have a DB trigger do it for you. No matter what, you're going to need some type of query to check for updates.
这将取决于确定统计信息是否更新的查询密集程度。如果它是一个简单(快速)的查询,那么这将是最好的选择。如果这是一个昂贵的查询,请更改统计信息的更新方式,以便您设置日期戳或让DB触发器为您执行此操作。无论如何,您将需要某种类型的查询来检查更新。
And you can't "push" from server to client either, so no matter what you'll need ajax polling so the client initiates the check....
并且你也不能从服务器“推送”到客户端,所以不管你需要什么样的ajax轮询,所以客户端启动检查....