


Think-Swoole tutorial configuration, work process, Ctrip charm and understanding Swoole process mode
The following tutorial column will introduce you to the configuration, working process, Ctrip charm and understanding of the Swoole process mode of the Think-Swoole tutorial. I hope it will be helpful to friends in need! Think-Swoole configuration, work process, Ctrip charm and understanding Swoole process mode
Configuration file:app/config/swoole.php'server' => [
'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址
'port' => env('SWOOLE_PORT', 9501), // 监听端口
'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS
'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP
'options' => [ // 都是给 Swoole 服务的配置,可以根据 Swoole 手册额外增加其它的 Swoole 配置
'pid_file' => runtime_path() . 'swoole.pid', //服务启动以后进程 ID 存放文件
'log_file' => runtime_path() . 'swoole.log', //Swoole 的日志文件
'daemonize' => false, //守护进程模式设置,true 后台运行
// Normally this value should be 1~4 times larger according to your cpu cores.
'reactor_num' => swoole_cpu_num(), //后台启动的 Reactor 线程数
'worker_num' => swoole_cpu_num(), //设置启动的 Worker 进程数
'task_worker_num' => swoole_cpu_num(), //配置 Task 进程数
'enable_static_handler' => true, //开启静态文件请求处理功能,需配合 document_root
'document_root' => root_path('public'), //配置静态文件根目录
'package_max_length' => 20 * 1024 * 1024, //设置最大数据包尺寸,单位为字节
'buffer_output_size' => 10 * 1024 * 1024, //配置发送输出缓存区内存尺寸
'socket_buffer_size' => 128 * 1024 * 1024, //用于设置客户端连接最大允许占用内存数量
],
],
'worker_num' => swoole_cpu_num(),
This configuration is to set the working process. swoole_cpu_num() is to get the number of local CPU cores. If it is manually set to 1, then There are two requests that need to be processed at the same time. Only one can be processed at a time, and the other is in a waiting state. After the first one is processed, the second one will be processed immediately, but they still belong to the same process. The process numbers of the two requests are the same. of. How to set it to 2, then 2 requests can be processed at the same time, and there will be two different process numbers.
CoroutineIn the Swoole configuration file, there is another option to configure the coroutine: 'coroutine' => [
'enable' => true,
'flags' => SWOOLE_HOOK_ALL,
],
Configure the number of working processes to 1, then start the service through the command php think swoole, open a new command window and execute ps -ef | grep swoole Check the process status, as shown in the figure below:
When Swoole starts, it will first start a master main process, and then start a manager management sub-process. These two processes The requested work will not be processed, and the processing of the request is handed over to the manager's sub-process worker. As can be seen in the above figure, the process number of the master main process is 30665, the parent process of the manager sub-process 30666 is 30665, and the parent processes of the task process and worker process are both 30666.Configure the number of worker processes to 2, restart the Swoole service, and check the process status again:
Execute pstree -p 31568, you can get the following relationship diagram:
The above is the detailed content of Think-Swoole tutorial configuration, work process, Ctrip charm and understanding Swoole process mode. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











Performance optimization and debugging of TP6Think-SwooleRPC service 1. Introduction With the rapid development of the Internet, distributed computing has become an indispensable part of modern software development. In distributed computing, RPC (RemoteProcedureCall, Remote Procedure Call) is a commonly used communication mechanism through which method calls across the network can be implemented. Think-Swoole, as a high-performance PHP framework, can support RPC services well. but

TP6 (ThinkPHP6) is an open source framework based on PHP, which has the characteristics of high scalability and distributed deployment. This article will introduce how to use TP6 with Swoole extension to build a highly scalable RPC service, and give specific code examples. First, we need to install TP6 and Swoole extensions. Execute the following command in the command line: composerrequiretopthink/thinkpeclinstallswo

Data encryption and identity authentication mechanism of TP6Think-SwooleRPC service With the rapid development of the Internet, more and more applications need to make remote calls to realize data interaction and function calls between different modules. In this context, RPC (RemoteProcedureCall) has become an important communication method. The TP6Think-Swoole framework can implement high-performance RPC services. This article will introduce how to use data encryption and identity authentication.

Highly concurrent request processing and scheduling of TP6Think-SwooleRPC service With the continuous development of Internet technology, concurrent request processing and scheduling of network applications has become an important challenge. In the TP6 framework, the Think-Swoole extension can be used to implement high-concurrency request processing and scheduling of the RPC (RemoteProcedureCall) service. This article will introduce how to build a Think-Swoole-based RPC service in the TP6 framework and provide

Integration and application of TP6Think-Swoole's RPC service and message queue In modern software development, RPC service (RemoteProcedureCall) and message queue are common technical means used to implement service calls and asynchronous message processing in distributed systems. Integrating Think-Swoole components in the TP6 framework can easily implement the functions of RPC services and message queues, and provides concise code examples for developers to understand and apply. 1. RPC

Security protection and authorization verification of TP6Think-SwooleRPC service With the rise of cloud computing and microservices, remote procedure call (RPC) has become an essential part of developers' daily work. When developing RPC services, security protection and authorization verification are very important to ensure that only legitimate requests can access and call the service. This article will introduce how to implement security protection and authorization verification of RPC services in the TP6Think-Swoole framework. 1. Basic concepts of RPC services

Introduction to the practical case of RPC service and microservice architecture built by TP6Think-Swoole: With the rapid development of the Internet and the expansion of business scale, the traditional monolithic architecture can no longer meet the needs of large-scale business scenarios. Therefore, the microservice architecture came into being. In the microservice architecture, the RPC (RemoteProcedureCall) service is an important way to achieve communication between services. Through RPC services, various microservices can call each other conveniently and efficiently. In this article

Performance testing and performance tuning of TP6Think-SwooleRPC service 1. Introduction With the rapid development of the Internet, the application of distributed systems is becoming more and more widespread. In distributed systems, RPC (Remote Procedure Call) is a common communication mechanism, which allows services on different nodes to call each other and achieve collaborative work in distributed systems. In the TP6 framework, Think-Swoole, as a high-performance Swoole driver, provides convenient RPC service support. This article mainly introduces T
