是不是坏主意,使一个AJAX调用后每2秒? [英] Is it bad idea to make an AJAX post call every 2 secs?

查看:159
本文介绍了是不是坏主意,使一个AJAX调用后每2秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我做一个AJAX $ .post的调用(使用jQuery)的PHP文件更新某个参数/数,是否认为不好的做法,危险或类似的?

If I make an AJAX $.post call (with jQuery) to a php file for updating a certain parameter/number, does it considered bad practise, dangerous or similar?

$.post(file.php, {var:var}, function(data){
// something
}, json);

这将是一个单独的页面通过点击一个对象更新一个数字上的单个用户。例如,如果用户A通过单击对象用户B的应立即看到此更新无需重新加载页面更新一定数量。

It would be a single user on a single page updating a number by clicking on an object. For example if user A is updating a certain number by clicking on an object user B should see this update immediately without reloading the page.

推荐答案

这取决于三个主要因素:

It depends on 3 main factors:

  1. 有多少用户,你在任何给定的时间?

  1. How many users will you have at any given time?

有多少数据是每个请求被发送平均?

How much data is being sent per request on average?

由于1和2,是你断绝设置来处理样的行动?

Given 1 and 2, is your sever set up to handle that kind of action?

我有一个的成立,以处理最多可同时10-20K用户的web应用程序,发出一个请求(可能是超过每秒1 REQ),并把它发送大约1000字节对每个请求。我得到一个平均的10毫秒响应时间,但是这是与节点JS。本来我开始在PHP中的项目,但它竟然是我的需要太慢了。

I have a webapp that's set up to handle up to 10-20k users simultaneously, makes a request each time the user changes a value on their page (could be more than 1 req per second), and it sends roughly 1000 bytes on each request. I get an average of 10ms response time, however that's with node js. Originally I started the project in PHP but it turned out to be too slow for my needs.

我不认为网络插座是正确的工具,你在做什么,因为你不需要服务器发送到客户端,并持续连接可以比发送请求每个要贵得多几秒钟。

I don't think web-sockets is the right tool for what you're doing, since you don't need the server to send to the client, and a constant connection can be much more expensive than sending a request every few seconds.

只是一定要做大量的测试,然后你可以对是否将制定出或不适合您的特定需求的判断。

Just be sure to do lots of testing and then you can make judgements on whether it'll work out or not for your specific needs.

TL;博士 - 这不是一个好主意,如果你的服务器不能处理它。否则,没有什么不妥的地方。

tl;dr - It's not a good idea if your server can't handle it. Otherwise, there's nothing wrong with it.

这篇关于是不是坏主意,使一个AJAX调用后每2秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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