Commit 3ae72846 authored by Jamie Carl's avatar Jamie Carl 🤙🏼

Updated code as per the Hazaar coding standard.

parent 0d19792f
......@@ -5,67 +5,102 @@ namespace Hazaar;
class Thread {
private $pref; // Process reference
private $pipes; // STDIO
private $buffer; // Output buffer
private $start; // Execute start time
private function Thread() {
$this->pref = 0;
$this->buffer = "";
$this->pipes = (array)NULL;
$this->start = time();
}
public static function Create( $file, $stderr = null ){
if( ! $stderr ) $stderr = array( "pipe", "w" );
if( ! $stderr )
$stderr = array( "pipe", "w" );
$t = new Thread;
$descriptor = array( 0 => array( "pipe", "r" ), 1 => array( "pipe", "w" ), 2 => $stderr );
$t->pref = proc_open( "php -q $file ", $descriptor, $t->pipes );
stream_set_blocking( $t->pipes[1], 0 );
return $t;
}
public function isActive(){
$this->buffer .= $this->listen();
$f = stream_get_meta_data( $this->pipes[1] );
return !$f["eof"];
}
public function Close(){
$r = proc_close( $this->pref );
$this->pref = NULL;
return $r;
}
public function Tell( $thought ) {
fwrite( $this->pipes[0], $thought );
}
public function Listen(){
$buffer = $this->buffer;
$this->buffer = "";
while( $r = fgets( $this->pipes[1], 1024 ) ){
while( $r = fgets( $this->pipes[1], 1024 ) )
$buffer .= $r;
}
return $buffer;
}
public function getError(){
$buffer = "";
while( $r = fgets( $this->pipes[2], 1024 ) ){
while( $r = fgets( $this->pipes[2], 1024 ) )
$buffer .= $r;
}
return $buffer;
}
public function getStartTime(){
return $this->start;
}
public function getRunTime(){
return ( time() - $this->start );
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment