PHP Daemon Development-use QPM to manage PID files

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.