Gonzalez Posted September 7, 2009 Report Posted September 7, 2009 <?phpclass Thread { var $pref ; // process reference var $pipes; // stdio var $buffer; // output buffer function Thread() { $this->pref = 0; $this->buffer = ""; $this->pipes = (array)NULL; } function Create ($file) { $t = new Thread; $descriptor = array (0 => array ("pipe", "r"), 1 => array ("pipe", "w"), 2 => array ("pipe", "w")); $t->pref = proc_open ("php -q $file ", $descriptor, $t->pipes); stream_set_blocking ($t->pipes[1], 0); return $t; } function isActive () { $this->buffer .= $this->listen(); $f = stream_get_meta_data ($this->pipes[1]); return !$f["eof"]; } function close () { $r = proc_close ($this->pref); $this->pref = NULL; return $r; } function tell ($thought) { fwrite ($this->pipes[0], $thought); } function listen () { $buffer = $this->buffer; $this->buffer = ""; while ($r = fgets ($this->pipes[1], 1024)) { $buffer .= $r; } return $buffer; } function getError () { $buffer = ""; while ($r = fgets ($this->pipes[2], 1024)) { $buffer .= $r; } return $buffer; }}?> Quote