Unfortunately that still doesn't have an affect.
This is the Process class I wrote for the task:
PHP Code:
<?php
class Process{
protected $Descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('file', 'error-output.txt', 'a'));
public $Pipes;
protected $Process;
protected $Open = false;
function __Construct($FileName){
$this->Process = proc_open('"'.$FileName.'"', $this->Descriptors, $this->Pipes, GetCWD());
stream_set_timeout($this->Pipes[1], 5);
stream_set_blocking($this->Pipes[1], 0);
$this->Open = true;
}
function IsOpen(){
return $this->Open;
}
function getError(){
return fgets($this->Pipes[2]);
}
function ReadLine(){
if($this->IsOpen())
return fgets($this->Pipes[1]);
else
return false;
}
function ReadLines($LineCount){
if(!$this->IsOpen()) return false;
$Lines = array();
for($i = 0; $i < $LineCount; $i++){
$Lines[] = $this->ReadLine();
}
return $Lines;
}
function CanRead(){
return ($this->IsOpen() && !feof($this->Pipes[1]));
}
function Read(){
if(!$this->IsOpen()){
return false;
}else{
return fgetc($this->Pipes[1]);
}
}
function ReadBlock(){
if(!$this->IsOpen()) return false;
$String = '';
while(!feof($this->Pipes[1])){
$String .= fgets($this->Pipes[1]);
}
return $String;
}
function WriteLine($String){
if($this->IsOpen())
return $this->Write($String . "\n");
}
function Write($String){
if($this->IsOpen())
return fwrite($this->Pipes[0], $String);
}
function GetStatus(){
return proc_get_status($this->Process);
}
function __Destruct(){
if($this->IsOpen())
proc_close($this->Process);
$this->Open = false;
}
}
and upon using it:
PHP Code:
<?php
$Process = new Process('TheFile.exe');
$Process->ReadBlock(); //Freezes PHP
//or:
$Process->ReadLines(30); //Fine if the number of lines is 30. If it's more, not all data is returned - if it's less, the application freezes.
The actual deadlock here is definitely in the reading of the stream.
Say there are 120 lines to be read. If I read 120, the application works like a charm. If I attempt to read 121, it doesn't return false and set eof like one would expect; Instead it simply freezes. Even if it's not in a feof loop, it still freezes simply by trying to get one more character.
Bookmarks