惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - AuOK?

深夜发文,惨痛教训,在redis集群中,不能使用 multi docker-compose 记录一个让人抓狂的错误 SVN 同一个仓库下,不同目录的自动更新方法 写点正则表达式的 MySQL 事务嵌套的方法 go mod PHP笔记 NGINXConfig windows 下修改文件属性值 nextcloud 应用开发 记录一下搞nextcloud的辛酸事吧 nextcloud环境搭建及部署 docker容器内访问宿主机,访问不通 错误:Host is unreachable 记录一下SQL的行行比较 记录一次nginx平滑升级 letsencrypt免费SSL证书自动续期 openresty lua-nginx-module模块中文文档 记录一下,php正则获取字符串子串技巧 nginx localhost的坑
守护进程因echo挂掉的原因,以及重定向标准输入、标准输出和标准错误
AuOK? · 2021-03-30 · via 博客园 - AuOK?

我自己的理解:

守护进程必然是要脱离终端的,而echo需要有标准输出,如果守护进程关闭了标准输出,或者关闭了终端,却没有重定向标准输出,那么,此时,在进程里进行echo,就会找不到标准输出而挂掉。

在php cli 的守护进程中,重定向标准输入,标准输出和标准错误。

1 fclose(STDIN);
2 fclose(STDOUT);
3 fclose(STDERR);
4 
5 global $STDIN,$STDOUT, $STDERR;
6 $STDIN   = fopen("/dev/null","r");
7 $STDOUT  = fopen("/var/log/stdout.log","wb");
8 $STDERR  = fopen("/var/log/stderr.log","wb");

在类似Unix的系统中,如果关闭了标准输出,标准错误输出文件描述符,那么重新打开的前三个文件描述符(相同顺序)将成为新的标准输入、输出、错误的描述符。

其中,变量设置成全局变量,避免在其它地方被释放掉。

来源:https://stackoverflow.com/questions/6472102/redirecting-i-o-in-php