当前位置:编程学习 > php >>

php 后端socket服务长链接,多并发开发备忘


[php]
       //保证子进程上限  
        if($this->_maxFork >0  && $this->_children > $this->_maxFork) 
        { 
            Yii::log("_children > ".$this->_maxFork,CLogger::LEVEL_WARNING,__METHOD__); 
            $this->handler(SIGCHLD); 
               usleep(200); 
            continue; 
        } 
 
 
/**
 * 监控信号
 * @param object socket $clientt
 * @return boolean
 */ 
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; 
    } 

            //保证子进程上限
            if($this->_maxFork >0  && $this->_children > $this->_maxFork)
            {
                Yii::log("_children > ".$this->_maxFork,CLogger::LEVEL_WARNING,__METHOD__);
                $this->handler(SIGCHLD);
//                 usleep(200);
                continue;
            }


    /**
     * 监控信号
     * @param object socket $clientt
     * @return boolean
     */
    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:
                //异常退出
 &nbs

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,