Home > PHP Framework > Swoole > Is swoole asynchronous?

Is swoole asynchronous?

(*-*)浩
Release: 2019-12-09 10:17:37
Original
1888 people have browsed it

Is swoole asynchronous?

swoole is PHP's asynchronous, parallel, high-performance network communication engine. It is written in pure C language and provides an asynchronous multi-threaded server in PHP language and an asynchronous TCP/UDP network. Client, asynchronous MySQL, asynchronous Redis, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, asynchronous DNS query.

Swoole has built-in Http/WebSocket server/client and Http2.0 server. (Recommended learning: swoole video tutorial)

Swoole can be widely used in the Internet, mobile communications, enterprise software, online games, Internet of Things, Internet of Vehicles, smart homes and other fields. Using PHP Swoole as a network communication framework can greatly improve the efficiency of enterprise IT R&D teams and focus more on developing innovative products.

Swoole has a built-in asynchronous non-blocking, multi-threaded network IO server at the bottom. PHP programmers only need to handle event callbacks and do not need to care about the underlying layer.

Unlike fully asynchronous frameworks such as Nginx/Tornado/Node.js, Swoole supports both fully asynchronous and synchronous.

When to use synchronization and when to use asynchronous. Explain it here.

We do not agree to use asynchronous callbacks for function development. The traditional PHP synchronization method to implement functions and logic is the simplest and best solution. Calling everywhere like node.js just sacrifices maintainability and development efficiency.

But sometimes it is suitable to use asynchronous, such as FTP, chat server, smtp, proxy server, etc. Server programs that mainly focus on communication and reading and writing disks, followed by functions and business logic.

"PHP's extension function API is all synchronous", this statement is not correct. In fact, the main places where synchronization is blocked are network calls and file reading and writing.

For example, mysql_query needs to communicate with the mysql database server, curl needs to call the network, file_get_contents needs to read and write files, and other fopen/fwrite/fread/fgets/fputs are blocking APIs. In addition, PHP's array/string/mbstring and other functions are non-blocking.

swoole provides asynchronous socket client, asynchronous mysql, and 1.6.12 also provides asynchronous file reading and writing and asynchronous DNS query functions. In addition, the task/finish API is provided, which can completely solve the blocking IO problem.

The above is the detailed content of Is swoole asynchronous?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template