/**
* Read the stdout pipe from Lazarus process. This function uses
* stream_select to be non blocking
*
* @return void
*/
public function tick()
{
$stream = $this->application->process->stdout->stream;
$read = [$stream];
$write = [];
$except = [];
$result = stream_select($read, $write, $except, 0);
if ($result === false) {
throw new Exception('stream_select failed');
}
if ($result === 0) {
return;
}
// This solves a bug on Windows - If you read the exact size (> 1),
// PHP will block
if (OsDetector::isWindows()) {
$status = fstat($stream);
if ($status['size'] > 0) {
$size = $status['size'];
if ($size > 1) {
$size -= 1;
$data = stream_get_contents($stream, $size);
$data .= stream_get_contents($stream, 1);
} else {
$data = stream_get_contents($stream, 1);
}
$this->application->process->stdout->emit('data', array($data, $this));
}
} else {
// On Linux and OSX, we don't need to pass a size limit
$data = stream_get_contents($stream);
if (!empty($data)) {
$this->application->process->stdout->emit('data', array($data, $this));
}
}
}