Javascript-ajax request termination, how to let the request of PHP also terminated??

Source: Internet
Author: User

I have done a Web-page search function.

The search is initiated by the foreground, and the search results are returned in the background.

Hit the folder search, and folders under the number of files (more than 20,000), the search time is very long (2 minutes or so to get results), sometimes I have no patience to wait, on the point stop search.

  // 终止搜索  stopSearch: function(){    console.log('xhr请求集合: ' , this.reqList);    for (var i = 0; i < this.reqList.length; ++i)      {        if (this.reqList[i].readyState !== 0 || this.reqList[i].status !== 200) {          this.reqList[i].abort();        }      }  }   

After clicking Stop Search, it is true that the foreground is stopped:

But the background php script is still running (and I set the PHP script to run the maximum time of 3min), each page refresh and so long (1min more), this is still relatively honest case (only launched a), if the bird fire, the mouse mad point, that estimate I had to restart the server ... Khan (The following is the result of the mad point, only point two or three times, the longest request time will reach 5min ... )!

Is there any way to terminate the operation of the background PHP script when the request is stopped?

Reply content:

I have done a Web-page search function.

The search is initiated by the foreground, and the search results are returned in the background.

Hit the folder search, and folders under the number of files (more than 20,000), the search time is very long (2 minutes or so to get results), sometimes I have no patience to wait, on the point stop search.

  // 终止搜索  stopSearch: function(){    console.log('xhr请求集合: ' , this.reqList);    for (var i = 0; i < this.reqList.length; ++i)      {        if (this.reqList[i].readyState !== 0 || this.reqList[i].status !== 200) {          this.reqList[i].abort();        }      }  }   

After clicking Stop Search, it is true that the foreground is stopped:

But the background php script is still running (and I set the PHP script to run the maximum time of 3min), each page refresh and so long (1min more), this is still relatively honest case (only launched a), if the bird fire, the mouse mad point, that estimate I had to restart the server ... Khan (The following is the result of the mad point, only point two or three times, the longest request time will reach 5min ... )!

Is there any way to terminate the operation of the background PHP script when the request is stopped?

No, all you can do is optimize your search performance.

Only from optimized search performance up and down. The HTTP protocol does not have a request to terminate the request to the background, and if the front-end server is Nginx, the PHP application server does not even know that the client has disconnected.
In this case, you can only start by optimizing the background.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.