PHP uses processes as daemon methods. PHP uses process as the Daemon. This article mainly introduces PHP's method of using process as the Daemon. The example analyzes the implementation skills of the daemon process in php, some reference prices for PHP methods to use processes as daemon processes
This article mainly introduces how PHP uses the process as the daemon process. The example analyzes the implementation skills of the daemon process in php and has some reference value. if you need it, refer
This example describes how PHP uses a process as a daemon. Share it with you for your reference. The specific analysis is as follows:
Usage of posix_setsid () in php
The document explains "Make the current process a session leader"
Reference: http://linux.die.net/man/2/setsid
This means that the process that calls this function between a process Group (parent process and child process) will be elected as the leader of the process Group.
So the way to make a process a daemon is:
1 fork generates a sub-process
2 in the sub-process posix_setsid ()
3. exit the parent process.
This document provides an example:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
$ 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 <= 60; $ I ++) {// do something for 5 minutes
Sleep (5 );
}
}
?>
|
I hope this article will help you with php programming.
This article describes how to use the process as a daemon in PHP. The example analyzes the implementation skills of the daemon in php and provides reference prices...