When writing a daemon program, we can use a PID file to mark whether a process has been created, to prevent the process from being restarted, and the PID file to record the process number in order to send a signal to the process. The Pidfile in QPM is the module used to manage PID files.
Example:
#pid_main. php Start (); while (true) sleep (10); > For the first time executing PHP pid_main.php, we can see that the Pid_main.php.pid file is generated and the process continues to run. Execute PHP pid_main.php Again, the script is wrong, the prompt process already exists. Fatal error:uncaught exception ' qpm\pidfile\exception ' with message ' process exists, no need to start a new one ' in .../q pm/pidfile/manager.php:41
In addition, Qpm\pid\manager also has a getprocess method.
#pid_check. php!--? php $man = new Manager (__dir__. '/pid_main.php.pid '); Echo $man--- GetProcess ()->getpid ();? > If the PID file does not exist or is empty, an exception is thrown. Note: The GetProcess method obtains an object that is not 100% guaranteed to be the original process. Subsequent versions will improve the detection here.
Above introduces PHP daemon development-using QPM to manage PID files, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.