PHP脚本来写Daemon程序
时间:2012-03-26 19:52:07 作者: 来源:
点击:
print "Worker start running ... n"; sleep(5); print "Worker's task done ... n"; $flag = TRUE; //Job status flag AutoStart( $signal_flag ); } function signal_handler( $signal ) { global $job_flag; global $signal_flag; switch( $signal ){ case SIGQUIT: print date('y-m-d H:i:s', time() ) . " Caught Signal : SIGQUIT - No : $signal n"; exit(0); break; case SIGSTOP: print date('y-m-d H:i:s', time() ) . " Caught Signal : SIGSTOP - No : $signal n"; break; case SIGHUP: print date('y-m-d H:i:s', time() ) . " Caught Signal : SIGHUP - No : $signal n"; if( $flag === TRUE ){ AutoStart( TRUE ); }else{ $signal_flag = TRUE; } break; case SIGALRM: print date('y-m-d H:i:s', time() ) . " Caught Signal : SIGALRM - No : $signal n"; //pcntl_exec( '/bin/ls' ); pcntl_alarm( 5 ); break; default: break; } } function AutoStart( $signal = FALSE, $filename =