ajax polling causing browser memory to increment every time
我想大声告诉你
我想大声告诉你 2017-05-24 11:33:53
0
4
855

ajax polling causes the browser memory to increase each time. I also checked the relevant information and it was said in complete

Complete ajax code:

    var Timer_getlastLog,ajax_flag;
    Timer_getlastLog = setInterval(function () {
        if(ajax_flag==true){
            getLastLog(lastMsgId);
        }
    }, 1000);
    function getLastLog(msgid) {
        ajax_flag = false;
        $.ajax({
            type: 'post',
            dataType: 'json', 
            url: 'url.html', 
            data: {msgid: msgid}, 
            success: function (a) {
                //此处省略其他的业务逻辑
                lastMsgId=a.msgid;
                ajax_flag = true;
            },
         
        });
    }    

Like this, but the memory overhead is still increasing,

Now I have almost run 2 G. Don't know any solution? Ignore sockets for now.

Supplement:
1. On the server side, I use the TP framework, and then I considered giving a while (true) and then a sleep(1); but this resulted in apache memory overhead after repeatedly refreshing the page. A large increase causes congestion and the page cannot be loaded and displayed normally. This also gives me a headache.

2. I refer to http://blog.csdn.net/mlx212/a... This article makes business modifications to this code and does not affect the logic.

我想大声告诉你
我想大声告诉你

reply all(4)
大家讲道理

Ask the question, this is no longer polling, it is infinite recursion, which will crash the computer; polling has a timed interval, setInterval.

仅有的幸福

There is a problem with your code. Polling only puts pressure on the server. The front-end access interface is the same as usual

我想大声告诉你

Looking at the link you gave me, regardless of error or success, it will execute itself. Isn’t this infinite recursion?

PHPzhong

No need to recurse, use setInterval

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template