Home  >  Article  >  Backend Development  >  Four ways of asynchronous execution in php

Four ways of asynchronous execution in php

王林
王林Original
2020-01-16 17:40:556388browse

Four ways of asynchronous execution in php

1. Use Ajax and img tag

Principle: Insert Ajax code or img tag into the HTML returned by the server, and the src of img is the program that needs to be executed.

Advantages: Simple implementation, the server does not need to perform any calls.

Disadvantages: During execution, the browser will always be in the loading state, so this method is not a true asynchronous call.

Four ways of asynchronous execution in php

(Free video tutorial recommendation: php video tutorial)

2. Use popen

Use popen to execute Command, syntax:

Four ways of asynchronous execution in php

Advantages: Fast execution

Disadvantages:

1. Can only be executed on this machine

2. You cannot pass a large number of parameters

3. Many processes will be created when the traffic is high

3. Use curl

to set the curl timeout CURLOPT_TIMEOUT to 1 (minimum is 1), so the client needs to wait 1 second.

Four ways of asynchronous execution in php

4. Using fsockopen

fsockopen is the best. The disadvantage is that you need to splice the header part yourself.

Four ways of asynchronous execution in php

Four ways of asynchronous execution in php

Note: During the execution process, the client connection is disconnected or the connection times out, which may cause incomplete execution, so it is necessary to Plus.

Four ways of asynchronous execution in php

Recommended related articles and tutorials: php tutorial

The above is the detailed content of Four ways of asynchronous execution in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn