Home>

I use windows7.
I want to reduce the CPU usage of Task Manager.

Calling php1 to php4 in ajax while looping every 0.5 seconds or every second in javascript.

$(function () {
  setInterval (function () {
    Invoking php1 with ajax
    Invoking php2 with ajax
    Invoking php3 with ajax
    Invoking php4 with ajax
  }, 1000);
});

See here I changed it to setTimeout, but it doesn't seem to loop once.

$(function () {
  function test () {
    Invoking php1 with ajax
    Invoking php2 with ajax
    Invoking php3 with ajax
    Invoking php4 with ajax
  }
  setTimeout (test, 1000);
});
Or
  function test () {
    Invoking php1 with ajax
    Invoking php2 with ajax
    Invoking php3 with ajax
    Invoking php4 with ajax
  }
  setTimeout (test, 1000);

In the first place, will CPU usage decrease if setInterval is changed to setTimeput?

Is there anything that reduces CPU usage?

  • Answer # 1

    Even if you simply lower the CPU usage, it doesn't make sense unless you first check which process is increasing the CPU usage.

    Are browsers really boosting CPU usage?

  • Answer # 2

    https://StackOverflow.com/questions/140960

    $(function () {
      function test () {
        Invoking php1 with ajax
        Invoking php2 with ajax
        Invoking php3 with ajax
        Invoking php4 with ajax
        setTimeout (test, 1000);
      }
      test ();
    });

    The above code was only proposed as "heavy processing" at the time of the previous question, so it was proposed. If ajax is involved, the problem of the previous question cannot be solved.

    If each call does not return in 1000ms or less, a lot of useless rewriting will occur.
    Depending on what the content is, using Promise may reduce unnecessary php calls. (Depending on requirements)

    [Now it's late but it's a Promise introduction]
    https://qiita.com/koki_cheese/items/c559da338a3d307c9d88