Php background daemon + process signal processing

Source: Internet
Author: User
Php background daemon + process signal processing
 0) {exit (0); // the parent process exits} // The Child process becomes the new session leader posix_setsid (); // disables the first child process from opening the control terminal, you need to create a second sub-process. I do not know how it works. $ pid = pcntl_fork (); if ($ pid =-1) {exit ("fork2 failed! \ N ") ;}elseif ($ pid> 0) {exit (0) ;}echo" process id :". posix_getpid (). "\ n"; $ open = true; function sig_handler ($ signo) {global $ open; switch ($ signo) {// custom signal SIGUSR1case SIGUSR1: echo "Hello, I continue to run \ n "; break; case SIGTERM: echo". when this cycle ends, I close \ n "; $ open = false; break; default: # code... break;} pcntl_signal (SIGUSR1, 'sig _ handler'); pcntl_signal (SIGTERM, 'sig _ handler'); // This line of code is very important, in this way, the signal can be checked every time a low-level statement is executed, otherwise the process signal declare (ticks = 1) cannot be detected in an infinite loop; while ($ open) {echo date ('Y-m-d H: I: s '). "\ n"; sleep (1);} echo "I exited 88"; exit;

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.