在jQuery中进行轮询是否昂贵,还有替代方案吗?
I have several users accessing my page at the same time, with each client polling (using setInverval) another php script that reads a value from a database and prints it.
setInterval( "printData();", 300 );
I'm relatively new to jQuery and javascript, and I'm a bit skeptical of the viability of constantly running this php script and constantly making database queries.
Can someone calm my nerves or provide an alternative to my current method?
我有几个用户同时访问我的页面,每个客户端轮询(使用 setInverval)另一个PHP脚本 从数据库中读取值并打印出来。 p>
setInterval(“printData();”,300);
code> pre>
\ n 我对jQuery和javascript相对较新,而且我对不断运行这个php脚本并不断进行数据库查询的可行性持怀疑态度。 p>
有人可以冷静吗? 我的神经或提供我当前方法的替代方案? p>
div>
You are updating it every 0.3 seconds - that's over 3 times a second. Way too much. Depending on how smooth it needs to be, update it at most every 5 seconds (5000
) instead.
Also, just to make it a little faster, just drop the quotes and parentheses:
setInterval(printData,5000);