PHP Timer Update Program Design Sharing

  • 2021-06-28 11:55:26
  • OfStack

In retrospect, I used to think incorrectly about how the web was executed

Open the WEB page - Load HTML code (including CSS, javascript) - Execute PHP code - Finish

Roughly, first understand it like this.

We all know that PHP is a server-side script that has a timeout and can be executed through set_time_The limit() function handles this.But handle PHP code like this for 10 minutes

Consumes CPU resources.Therefore, it is not recommended to loop through PHP code.

1 The general case is handled with javascript.


$(function(){
    var tims = 1000*60*60*10; // Set the time for delayed processing, which is set here 10 Hours 
      setInterval(function(){
    // Code to execute 
        $.post("./data.php",{ postdata },function(datas){
            if(id.data == 1)
            {
              $("body").append(id.info+"<br/>");
            }
     });
},tims);
    },json);

Above is the javascript code to be executed by the WEB foreground to achieve automatic processing by delaying the execution of ajax

php background processing code is simple, as long as you accept data from the foreground POST.The data is then processed and stored in the database.

It's that simple, but the page can't be closed, which you can understand as a software daemon.

In fact, one software is divided into: front-end, back-end, server-side.Both the front and back end are running on your computer.

Tencent Software Background Program
The daemon only monitors its arrival through the Task Manager, but what does it do?You don't know at all.

360 can steal your privacy like a worker bee, QQ can get cookie.

Not to mention, this is one of the software design modes, you can understand it.


Related articles: