日期:2014-05-16  浏览次数:20481 次

关于xajax的问题
xajax的注册函数如下
PHP code

function deal($form,$type)
{
    $objResponse=new xajaxResponse();
    $objResponse->alert( "formData: " . print_r( $form, true ) );
        //其他代码
        return $objResponse;
}


如果我在其他代码出不加入任何代码,很正常,会弹出alert框
但是如果我在其他代码处加上一些特定的代码:
PHP code

    $proc = new proc_mgr();
    if( !$proc->init() )
    {
        $objResponse->assign( "testdiv", "innerHTML", "init failed!");
        return $objResponse;
    }
    $proc->cmd("start 0");


具体的proc_mgr如下
PHP code

class proc_mgr
{
    private $process;
    private $descriptorspec;
    private $pipes;
    private $quit;
    private $sp;
    public function __construct()
    {
        $this->sp = CMD_BR;
        $this->quit = CMD_QUIT.CMD_BR;
        $this->descriptorspec = array(
           0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
           1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
           2 => array("file", PCC_DIR."/webpcc-err-log.txt","a") // stderr is a file to write to
        );
        //stream_set_blocking ( $this->descriptorspec, true);
    }
    public function __destruct()
    {    
        release();
    }
    public function init()
    {
        $this->process = proc_open(PCC_EXE, $this->descriptorspec,$this->pipes,PCC_DIR);
        if( !is_resource($this->process) )
        {
            return false;
        }
        return true;
    }
    public function release()
    {
        return proc_close($this->process);;
    }
    public function quitproc()
    {
        fwrite($this->pipes[0], $this->quit);
        fclose($this->pipes[0]);
        while ( !feof($this->pipes[1]) ) 
        {
            $result .= stream_get_contents($this->pipes[1]);
        }
        fclose($this->pipes[1]);
        return $result; 
    }
    public function cmd($strcmd)
    {
        $cmds = $strcmd.$this->sp.$this->quit;
        fwrite($this->pipes[0], $cmds);
        fclose($this->pipes[0]);
        $result = "";
        while ( !feof($this->pipes[1]) ) 
        {    
            //$result = $this->fgets($this->pipes[1], 4096);
            $result .= stream_get_contents($this->pipes[1]);
            //echo $result;
        }
        fclose($this->pipes[1]);
        return $result;
    }
        
    public function cmds($listcmd)
    {
        $count = count($listcmd);
        for( $i=0; $i<$count; ++$i )
        {
            $cmd .= $listcmd[$i];
            $cmd .= $this->sp;
        }
        $cmd .= $this->quit;
        return $this->cmd($cmd);
    }
}


也就是只要加入了proc_mgr相关代码后,xajaxResponse的所有方法(alert assign)都失效了,求高手解答,万分感谢

------解决方案--------------------
表示没有用过!
------解决方案--------------------
if( !$proc->init() )
这里没通过,就是$proc->init() == false


 public function init()
{
$this->process = proc_open(PCC_EXE, $this->descriptorspec,$this->pipes,PCC_DIR);
if( !is_resource($this->process) )
{
return false;
}
return true;
}

检查这里的proc_open是不是有问题
------解决方案--------------------
第一段代码中 return $objResponse; 总是被执行的
而第二段代码中 return $objResp