better handling of timeout

This commit is contained in:
Uwe Steinmann 2017-03-01 16:18:27 +01:00
parent fab21da3d8
commit 2cfc080382
2 changed files with 10 additions and 9 deletions

View File

@ -31,24 +31,25 @@ class SeedDMS_Lucene_IndexedDocument extends Zend_Search_Lucene_Document {
2 => array("pipe", "w")
);
$pipes = array();
$timeout += time();
$timeout += time();
$process = proc_open($cmd, $descriptorspec, $pipes);
if (!is_resource($process)) {
throw new Exception("proc_open failed on: " . $cmd);
}
$output = '';
$timeleft = $timeout - time();
$read = array($pipes[1]);
$write = NULL;
$exeptions = NULL;
do {
$timeleft = $timeout - time();
$read = array($pipes[1]);
$write = NULL;
$exeptions = NULL;
stream_select($read, $write, $exeptions, $timeleft, 200000);
if (!empty($read)) {
$output .= fread($pipes[1], 8192);
}
}
$timeleft = $timeout - time();
} while (!feof($pipes[1]) && $timeleft > 0);
if ($timeleft <= 0) {

View File

@ -37,7 +37,7 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
);
$pipes = array();
$timeout += time();
$timeout += time();
$process = proc_open($cmd, $descriptorspec, $pipes);
if (!is_resource($process)) {
throw new Exception("proc_open failed on: " . $cmd);
@ -53,7 +53,7 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
if (!empty($read)) {
$output .= fread($pipes[1], 8192);
}
}
$timeleft = $timeout - time();
} while (!feof($pipes[1]) && $timeleft > 0);