stream_select 和 pcntl_signal 有冲突?

klggg 2013-04-19 03:44:35

调用了
pcntl_signal($signal, array(&$this, "handler"))
$mod_fd = stream_select($read,$write , $except , $tv_sec = 5);


运行后报如下错误,删除掉 pcntl_signal 后正常,请教是什么 原因,怎么解决 。


PHP Error[2]: stream_select(): unable to select [4]: 被中断的系统调用 (max_fd=10)

PHP 5.4.6-1ubuntu1.2 (cli) (built: Mar 11 2013 14:54:18)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans




$signals = array(
SIGCHLD => "SIGCHLD",
SIGCLD => "SIGCLD",
SIGINT => "SIGINT",
SIGHUP => "SIGHUP",
SIGQUIT => "SIGQUIT",
);

if (version_compare(phpversion(), "5.3.0", "lt")) {
// tick use required as of PHP 4.3.0
declare(ticks = 1);
}

foreach ($signals as $signal => $name) {
if (!pcntl_signal($signal, array(&$this, "handler"))) {
die("Install signal handler for {$name} failed");
}
}

...

$mod_fd = stream_select($read,$write , $except , $tv_sec = 5);






public function handler($signo) {

Yii::log("handler {$signo} ",CLogger::LEVEL_INFO, __METHOD__);

switch(intval($signo)) {
case SIGCLD:
case SIGCHLD:

Yii::log("SIGCHLD sub proccess ",CLogger::LEVEL_TRACE, __METHOD__);
//正常退出
//declare = 1, that means one signal may be correspond multi-process die
while( ($pid = pcntl_wait($status, WNOHANG|WUNTRACED)) > 0 ) {
if (FALSE === pcntl_wifexited($status)) {
Yii::log("sub proccess {$pid} exited unormally with code {$status}",CLogger::LEVEL_WARNING, __METHOD__);
} else {
Yii::log("sub proccess {$pid} exited normally",CLogger::LEVEL_INFO, __METHOD__);
}
$this->_children--;
}
break;
case SIGINT:
case SIGQUIT:
case SIGHUP:
//异常退出
$this->_cleanup();
exit(0);
break;
default:
break;
}
}





...全文
70 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
基础编程
加入

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
申请成为版主
帖子事件
创建了帖子
2013-04-19 03:44
社区公告
暂无公告