The example in this article describes how PHP processes a process as a daemon. Share to everyone for your reference. The specific analysis is as follows:
Usage of posix_setsid () in PHP
The document explanation is "make the current process a session leader"
Reference Document: Http://linux.die.net/man/2/setsid
This means that the process of calling this function between a group of processes (parent and child processes) will be elected as a leader of the process group
So the way to make a process a daemon is to:
1 Fork out a child process
2 in the subprocess Posix_setsid ()
3 Exiting the parent process
There is an example in the document:
<?php
$pid = Pcntl_fork ();//Fork
if ($pid < 0)
exit;
else if ($pid)//parent
exit;
else {//child
$sid = Posix_setsid ();
if ($sid < 0)
exit;
for ($i = 0; $i <= $i + +) {//do Something for 5 minutes sleep
(5);
}
? >
I hope this article will help you with your PHP program design.