Home  >  Article  >  Backend Development  >  The difference between PHP synchronization and asynchronous

The difference between PHP synchronization and asynchronous

藏色散人
藏色散人Original
2021-11-02 09:47:272975browse

The difference between synchronous and asynchronous PHP: 1. Traditional synchronous programming is a request response model, while asynchronous programming requires reconsideration of whether a response is required; 2. Synchronization means that there is a sequence between multiple tasks Sequential execution, while asynchronous means that there is no order between multiple tasks, they can be executed at the same time, etc.

The difference between PHP synchronization and asynchronous

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

The difference between PHP synchronization and asynchronousness

Synchronization: Multiple tasks are executed sequentially, and the next one can only be executed after one is executed.

Asynchronous: There is no order between multiple tasks and they can be executed at the same time. Sometimes a task may need to obtain the results of another task executed at the same time when necessary. This is called a callback!

Traditional synchronous programming is a request-response model, calling a method and waiting for its response to return.

Asynchronous programming is to reconsider whether a response is needed, that is, to narrow down the places where a response is needed. Because the faster you get a response, the more synchronized, sequential, transactional, and poorer the performance.

Asynchronous programming is usually implemented through fire and forget. After the event is emitted, it is forgotten and done with other things. There is no need to wait immediately for the response result just emitted. (The place where events are emitted is called a producer, and the handler that responds to events in another place is called a consumer). Asynchronous programming is a kind of event-driven programming, which requires a complete change of thinking from "request response" to The "event-driven" idea is a change in software programming thinking.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of The difference between PHP synchronization and asynchronous. 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