Use PHP to build your own stable and reliable daemon

藏色散人
Release: 2023-04-07 06:14:02
forward
3303 people have browsed it

Build a stable and reliable PHP daemon

what

##● pcntl_fork

● Process/Process Group/Group Long process/session

●Standard input/output/error

why

how

You need to install the pcntl extension to use it

● Background running

if ($pid=pcntl_fork ()) exit (0);// is the parent process, end the parent process , the child process continues

●Leave the control terminal, log in to the session and process group

posix_setsid ();//The child process upgrades the group leader process, and leaves the original session/terminal

● Prohibit the process from reopening the control terminal

if ($pid=pcntl_fork ()) exit (0);//End the first child process and the second child process continues (the second child process is no longer a session Team leader)

● Close the open file descriptor

fclose (STDIN), fclose (STDOUT), fclose (STDERR) // Close standard input and output and error display.

● Change the current working directory

chdir("/")

● Reset the file creation mask

umask (0);//Prevent Inherit the mask left by the parent

Related recommendations: "

PHP Tutorial"

The above is the detailed content of Use PHP to build your own stable and reliable daemon. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!