php 创建守护进程

来源:互联网 发布:artrage for mac 编辑:程序博客网 时间:2024/04/29 23:05
<?php    function signalHandler($signal) {global $worker_pid;     if ($signal == SIGINT) {    exec("rm -rf ".$worker_pid.'_start_id.pid',$worker_pid);        exit(0);    }    if ($signal == SIGTERM) {    exec("rm -rf ".$worker_pid.'_start_id.pid',$worker_pid);        exit(0);    }}$pid = pcntl_fork();if ( $pid < 0) {die('fork failed');} else if ( $pid > 0 ) {exit(0);}//在子进程注册信号pcntl_signal(SIGINT, 'signalHandler');pcntl_signal(SIGTERM, 'signalHandler');$worker_pid = posix_getpid();if ($worker_pid){file_put_contents($worker_pid.'_start_id.pid',$worker_pid);}while (1) {    //file_put_contents('data.txt',"write name:peen\n",FILE_APPEND);    file_get_contents("http://10.150.1.144/Api/Version2_0/VerfiyCode/sendSms"); //每1秒请求一次url    sleep(1);    pcntl_signal_dispatch();}

                                             
0 0