比这篇新的文章:
目前不成功的Twitter转校内日志工具
比这篇旧的文章: Change Logonui
作者: bit_kevin, 点击739次, 评论(0), 收藏者(0), , 打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: Change Logonui
确认进程唯一,防止死掉
语言: PHP, 标签: 无 2009/04/20发布 3年前更新作者: bit_kevin, 点击739次, 评论(0), 收藏者(0), , 打分:
PHP语言: 确认进程唯一,防止死掉
01 <?php
02
03 //确认进程唯一,防止死掉
04 function check_proc() {
05 if( $pidfile = @file_get_contents("./my.pid") )
06 {
07 list($pid, $last_time) = explode(",", $pidfile);
08 if( $link = @readlink("/proc/{$pid}/exe") )
09 {
10 if( time()-$last_time > 60*60 )//1 hour
11 {
12 //超时KILL掉那个进程
13 system("kill -9 {$pid}");
14 }else{
15 echo "already exist, process exit.\n";
16 exit;
17 }
18 }
19 }
20 //写入当前PID信息
21 file_put_contents("./my.pid", getmypid().','.time() );
22 }
23
24 ?>
02
03 //确认进程唯一,防止死掉
04 function check_proc() {
05 if( $pidfile = @file_get_contents("./my.pid") )
06 {
07 list($pid, $last_time) = explode(",", $pidfile);
08 if( $link = @readlink("/proc/{$pid}/exe") )
09 {
10 if( time()-$last_time > 60*60 )//1 hour
11 {
12 //超时KILL掉那个进程
13 system("kill -9 {$pid}");
14 }else{
15 echo "already exist, process exit.\n";
16 exit;
17 }
18 }
19 }
20 //写入当前PID信息
21 file_put_contents("./my.pid", getmypid().','.time() );
22 }
23
24 ?>
所有评论,共0条:( 我也来说两句)
代码
