English 中文(简体)
每秒从数据库获取数据的最佳途径(按时间顺序排列)
原标题:The best way to access data from a database every X seconds (asynchronously)

奥基先生,现在我确实没有提出这个问题,特别是没有标题。 但是,在试图与他人保持关系时,这给它一个足够具体的尝试和希望。

您想在背景(通过jax)中操作一套从数据库中恢复数据的分数X秒钟,而你如何在不使用大部分服务器资源的情况下以最佳方式这样做?

我的解决办法是:

用户访问一个网页,其页数为千字节。 javascript打着一个叫做PHP script/file的纸面,该书称数据库,检索数据并将数据退回到javascript。 然后将数据打印到网页上。 我担心的是,如果在网页上有大量(10 000名)同时访客,解决这一难题的办法将对服务器施加很大压力。 是否有其他办法这样做?

问题回答

鉴于你提出的猜测/要求,这种声音像最好的方式。

另一个办法是采取中间步骤。 如果您将拥有huge的交通量(否则不会带来任何好处,但相反会克服程序上的重复/缺陷),则增加另一个表格,记录数据集的最后一点,以及一个硬文档(例如XML),如果说最后一次是很久以前,它是由新的询问产生的,那么这一XML就将结果反馈给用户。

因此:

1.Javascript calls PHP script (AJAX)

2.PHP pings DB table which contained final time data was full production

3.If time is too great, main query is rerun and XML file is regenerated from output ELSE skip to 4

4.Fetch the XML file and potential for home AJAX

你可以采取另一种方式,在需要时与客户联系,浪费较少的资源。

Comet 这为这一选择铺平道路:

Comet is a programming technique that enables web servers to send data to the client without having any need for the client to request it. This technique will produce more responsive applications than classic AJAX. In classic AJAX applications, web browser (client) cannot be notified in real time that the server data model has changed. The user must create a request (for example by clicking on a link) or a periodic AJAX request must happen in order to get new data fro the server.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签