当前位置:网站首页>Talk about how to hot restart a spoole or PHP cli process
Talk about how to hot restart a spoole or PHP cli process
2022-06-25 23:47:00 【ndrandy】
Before discussing this topic , Need to know linux The signal of , stay linux The most common function used to initiate a signal in is kill 了 , Such as kill -SIGUSR1 pid、kill -9 pid 、kill -SIGTERM pid wait . These are soft interrupts
After the process receives these signals , Default processing behavior , That is to exit the process directly regardless of the three seven twenty-one , At this time, if the process is processing business data , So sorry , It's just gone . So how to deal with it ?
The core step
- Register signal processing functions , To intercept the signal received by the listening process , Change the default processing behavior of the process
- In the business layer code , Make a status mark , When the status is exitable , direct exit
The following is used php Simulation Implementation
<?php
$running = true;
pcntl_signal(SIGTERM, function () use (&$running) {
// received stop command , Mark the switch as exitable
$running = false;
// There is no direct exit
});
while ($running){
// Here the business data logic is handled
//do step.1
//do step.2
//do step.3
//do step.4
//do step.5
//do step.6
}
/**
* When the process receives SIGTERM Signal time ( namely :stop), The code logic may run to step.1 ~ step.6 Anywhere in between . received Letter
* Change immediately after the th $running= false, At this time, it is not direct exit, Guarantee this round while Finish the cycle , To the next round while When
* $running= false,while Loop exit , The process exits safely
*/
边栏推荐
- Summary of common JDBC exceptions and error solutions
- The software test interview has been suspended. The interviewer always says that the logical thinking is chaotic. What should I do?
- 请问可以不部署服务端实现图片上传吗?
- 7.常用指令(下)v-on,v-bind,v-model的常见操作
- CSDN force value
- php中使用Makefile编译protobuf协议文件
- Once beego failed to find bee after passing the go get command Exe's pit
- How does excel translate Chinese words into English automatically? This formula teaches you
- mysql
- mysql版本升级+数据迁移
猜你喜欢

流数据

权限设计=功能权限+数据权限

第六章 习题(678)【微机原理】【习题】

Online customer service - charging standards and service provision of third parties

line-height小用

解析產品開發失敗的5個根本原因

Kotlin空指针Bug

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

QT Chinese and English use different fonts respectively

final和static
随机推荐
iomanip头文件在实战中的作用
Px4 simulation basis
CSDN原力值
1.8 billion pixel Mars panorama Ultra HD released by NASA, very shocking
Blob
Ad20 learning notes II
YUV444、YUV422、YUV420、YUV420P、YUV420SP、YV12、YU12、NV12、NV21
Apache Doris1.0版本集群搭建、负载均衡与参数调优
Extraction system apk
Record the ideas and precautions for QT to output a small number of pictures to mp4
发送邮件工具类
idea 查看单元测试覆盖率
Once beego failed to find bee after passing the go get command Exe's pit
流数据
社招两年半10个公司28轮面试面经(含字节、拼多多、美团、滴滴......)
MySQL InnoDB锁知识点
第五章 习题(124、678、15、19、22)【微机原理】【习题】
解析產品開發失敗的5個根本原因
中序线索二叉树
Wireshark对IMAP抓包分析