How does the javascript-PHP server continuously return data to the client?

Source: Internet
Author: User
The situation is as follows: after the front-end confirms the operation, the server initiates an ajax request to receive the request and start to execute the business logic cyclically. However, the server processes a large number of cyclic business logic, which takes a long time: how to return data to the client after each loop to let the user know the current progress The situation is as follows:

  1. After the front-end confirms the operation, initiate an ajax request

  2. When the server receives the request, it starts to execute the business logic cyclically. However, the process involves a large amount of cyclic business logic and takes a long time.

Problem:

  1. How to return data to the client after each loop,Let the user know the current progress

Reply content:

The situation is as follows:

  1. After the front-end confirms the operation, initiate an ajax request

  2. When the server receives the request, it starts to execute the business logic cyclically. However, the process involves a large amount of cyclic business logic and takes a long time.

Problem:

  1. How to return data to the client after each loop,Let the user know the current progress

Common ajax and http cannot meet this requirement, which can be achieved through websocket. PHP is a mature swoole framework.

Push with websocket

The first two have already saidWebsocket.

Then I will fill in anotherServer sent events, AbbreviationSSE.
Your server can send data to the client in one way.

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.