通过递归函数和DDOS进行多次ajax调用 [英] Multiple ajax calls via recursive function and DDOS-ing ourselves

查看:96
本文介绍了通过递归函数和DDOS进行多次ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在链接中的注释中数组循环中的jquery多个Ajax请求作者说,在一个循环中发出ajax请求可能最终会导致DDOS-我们自己.

In the comment by the link Jquery multiple Ajax Request in array loop the author said that making ajax requests in a loop may end up DDOS-ing ourselves.

通常只应用一个循环或多个ajax调用吗?我的意思是,如果我通过递归函数(例如,

Does that apply only a loop or multiple ajax calls in general? I mean may the risk of DDOS-ing be as well if I make multiple ajax requests via recursive function like

ajax(0);

ajax(index) {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(this.readyState == 4 && this.status == 200) {
            ajax(index+1)
        }
    };
    xhr.open('POST', 'http://example.com/ajax_handler.php');
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
    xhr.send();
}

ps.我了解我们可以将所有数据聚合在一起,然后在单个请求中将其发送到服务器" ,但是我需要运行生成将数据从客户端传递到服务器的静态页面.因此,如果我必须通过AJAX传递成千上万的页面,由于POST请求的限制,它们不能作为一个请求传递.

ps. I understand that we can "congregate all data together then send that in a single request to the server", but I need to run generating static pages passing data from the client to the server. So if there are dozens of thousands of pages I must to pass to the server via AJAX, they can't be passing as one single request because of limit of POST requests.

为什么呢?我只想将生成器的所有逻辑保留在客户端,而仅在服务器上调用诸如读取和写入文件之类的标准操作.也就是说,客户端通过ajax和服务器读取功能读取模板和内容,根据其逻辑构建页面html,然后将整个html传递给服务器以写入html文件中.

Why so? I would just like to keep all the logic of the generator at the client and call at the server only standard operations like reading and writing files. That is the client reads templates and content via ajax and server reading function, build page html according to its logic and pass the whole html to the server to be written in a html file

推荐答案

Rory McCrossan所描述的问题是,如果您一次一次发出多个请求.如果您有很多个请求,则可能会使服务器(和/或网络连接)超载-您不应一次发出大量请求.(最好不要每秒向服务器发送5个以上的请求,或类似的请求.)

The problem Rory McCrossan was describing was if you make multiple requests at once. If you have lots of requests, you might overload the server (and/or your network connection) - you shouldn't make tons of requests at once. (Probably best to not send more than 5 request a second to a server, or something like that.)

但是在您的代码中,您并没有立即发出请求;您在任何时候最多只有一个一个请求处于活动状态,因此他描述的问题不是您需要担心的事情.

But in your code, you're not sending out the requests at once; you only have at most one request active at any time, so the issue he was describing isn't something you need to worry about.

那是

数十万个页面我必须通过AJAX传递到服务器

dozens of thousands of pages I must to pass to the server via AJAX

是一个很奇怪的要求,即使您没有使网络超载,也将需要大量带宽.考虑是否有更优雅的解决方案,例如仅在请求页面时才生成/发送页面.

is a pretty odd requirement and will require a lot of bandwidth even if you don't overload the network. Consider if there's any more elegant solutions to the problem, such as generating/sending a page only when that page is requested.

这篇关于通过递归函数和DDOS进行多次ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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