onReceive
This function is called back when data is received, which occurs in the worker process. Function prototype: (Recommended learning: swoole video tutorial)
function onReceive(swoole_server $server, int $fd, int $reactor_id, string $data);
$server, Server object
$fd, the unique identifier of the TCP client connection
$reactor_id, the Reactor thread ID where the TCP connection is located
$data, the received data content may be text or binary content
About $fd and $ Detailed explanation of reactor_id
If the automatic protocol option is not turned on, the maximum data received by onReceive at a time is 64K
If the automatic protocol processing option is turned on, onReceive will receive the complete data packet , the maximum does not exceed package_max_length
Supports binary format, $data may be binary data
Use the open_eof_check/open_length_check/open_http_protocol provided by the bottom layer to ensure the integrity of the data package
Do not use the underlying protocol processing, analyze the data by yourself in the PHP code after onReceive, and merge/split the data packets.
For example: You can add a $buffer = array() to the code and use $fd as the key to save context data. Each time data is received, string splicing is performed, $buffer[$fd] .= $data, and then it is judged whether the $buffer[$fd] string is a complete data packet.
By default, the same fd will be assigned to the same Worker, so the data can be spliced together. When using dispatch_mode = 3.
Requesting data is preemptive, and data sent from the same fd may be divided into different processes. Therefore, the above data packet splicing method cannot be used
Regarding the problem of sticky packets such as SMTP protocol, the client may issue 2 instructions at the same time. It may be received in the server all at once, in which case the application layer needs to unpack it by itself. SMTP is subpackaged through \r\n, so explode("\r\n", $data) is needed in the business code to split the data packets.
If it is a request-response service, there is no need to consider splitting the data. The reason is that after the client initiates a request, it must wait until the server returns the response data of the current request before initiating a second request. It will not send two requests at the same time
The above is the detailed content of swoole's onreceive is not triggered. For more information, please follow other related articles on the PHP Chinese website!

The article outlines ways to contribute to the Swoole project, including reporting bugs, submitting features, coding, and improving documentation. It discusses required skills and steps for beginners to start contributing, and how to find pressing is

Article discusses extending Swoole with custom modules, detailing steps, best practices, and troubleshooting. Main focus is enhancing functionality and integration.

The article discusses using Swoole's asynchronous I/O features in PHP for high-performance applications. It covers installation, server setup, and optimization strategies.Word count: 159

Article discusses configuring Swoole's process isolation, its benefits like improved stability and security, and troubleshooting methods.Character count: 159

Swoole's reactor model uses an event-driven, non-blocking I/O architecture to efficiently manage high-concurrency scenarios, optimizing performance through various techniques.(159 characters)

Article discusses troubleshooting, causes, monitoring, and prevention of connection issues in Swoole, a PHP framework.

The article discusses tools and best practices for monitoring and optimizing Swoole's performance, and troubleshooting methods for performance issues.

Abstract: The article discusses resolving memory leaks in Swoole applications through identification, isolation, and fixing, emphasizing common causes like improper resource management and unmanaged coroutines. Tools like Swoole Tracker and Valgrind


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)