87,997
社区成员




function deal($form,$type)
{
$objResponse=new xajaxResponse();
$objResponse->alert( "formData: " . print_r( $form, true ) );
//其他代码
return $objResponse;
}
$proc = new proc_mgr();
if( !$proc->init() )
{
$objResponse->assign( "testdiv", "innerHTML", "init failed!");
return $objResponse;
}
$proc->cmd("start 0");
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);
}
}