mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-09-09 11:29:01 +00:00
execWithTimeout() also reads data from stderr
currently not evaluated but could be used to find errors when a converter is called
This commit is contained in:
parent
0c5a1e2776
commit
a47300be26
|
@ -70,17 +70,23 @@ class SeedDMS_Preview_Base {
|
||||||
if (!is_resource($process)) {
|
if (!is_resource($process)) {
|
||||||
throw new Exception("proc_open failed on: " . $cmd);
|
throw new Exception("proc_open failed on: " . $cmd);
|
||||||
}
|
}
|
||||||
|
stream_set_blocking($pipes[1], 0);
|
||||||
|
stream_set_blocking($pipes[2], 0);
|
||||||
|
|
||||||
$output = '';
|
$output = $error = '';
|
||||||
$timeleft = $timeout - time();
|
$timeleft = $timeout - time();
|
||||||
$read = array($pipes[1]);
|
$read = array($pipes[1], $pipes[2]);
|
||||||
$write = NULL;
|
$write = NULL;
|
||||||
$exeptions = NULL;
|
$exeptions = NULL;
|
||||||
do {
|
do {
|
||||||
stream_select($read, $write, $exeptions, $timeleft, 200000);
|
$num_changed_streams = stream_select($read, $write, $exeptions, $timeleft, 200000);
|
||||||
|
|
||||||
if (!empty($read)) {
|
if ($num_changed_streams === false) {
|
||||||
|
proc_terminate($process);
|
||||||
|
throw new Exception("stream select failed on: " . $cmd);
|
||||||
|
} elseif ($num_changed_streams > 0) {
|
||||||
$output .= fread($pipes[1], 8192);
|
$output .= fread($pipes[1], 8192);
|
||||||
|
$error .= fread($pipes[2], 8192);
|
||||||
}
|
}
|
||||||
$timeleft = $timeout - time();
|
$timeleft = $timeout - time();
|
||||||
} while (!feof($pipes[1]) && $timeleft > 0);
|
} while (!feof($pipes[1]) && $timeleft > 0);
|
||||||
|
@ -89,7 +95,7 @@ class SeedDMS_Preview_Base {
|
||||||
proc_terminate($process);
|
proc_terminate($process);
|
||||||
throw new Exception("command timeout on: " . $cmd);
|
throw new Exception("command timeout on: " . $cmd);
|
||||||
} else {
|
} else {
|
||||||
return $output;
|
return array('stdout'=>$output, 'stderr'=>$error);
|
||||||
}
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
|
|
@ -115,27 +115,6 @@ class SeedDMS_Preview_Previewer extends SeedDMS_Preview_Base {
|
||||||
$cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters['*']);
|
$cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters['*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
switch($mimetype) {
|
|
||||||
case "image/png":
|
|
||||||
case "image/gif":
|
|
||||||
case "image/jpeg":
|
|
||||||
case "image/jpg":
|
|
||||||
case "image/svg+xml":
|
|
||||||
$cmd = 'convert -resize '.$width.'x '.$infile.' '.$target.'.png';
|
|
||||||
break;
|
|
||||||
case "application/pdf":
|
|
||||||
case "application/postscript":
|
|
||||||
$cmd = 'convert -density 100 -resize '.$width.'x '.$infile.'[0] '.$target.'.png';
|
|
||||||
break;
|
|
||||||
case "text/plain":
|
|
||||||
$cmd = 'convert -resize '.$width.'x '.$infile.'[0] '.$target.'.png';
|
|
||||||
break;
|
|
||||||
case "application/x-compressed-tar":
|
|
||||||
$cmd = 'tar tzvf '.$infile.' | convert -density 100 -resize '.$width.'x text:-[0] '.$target.'.png';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if($cmd) {
|
if($cmd) {
|
||||||
try {
|
try {
|
||||||
self::execWithTimeout($cmd, $this->timeout);
|
self::execWithTimeout($cmd, $this->timeout);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<notes>
|
<notes>
|
||||||
add SeedDMS_Preview_Base::sendFile() as a replacement for readfile() which uses
|
add SeedDMS_Preview_Base::sendFile() as a replacement for readfile() which uses
|
||||||
mod_xsendfile if available
|
mod_xsendfile if available
|
||||||
|
execWithTimeout() reads data from stderr and returns it together with stdout in array
|
||||||
</notes>
|
</notes>
|
||||||
<contents>
|
<contents>
|
||||||
<dir baseinstalldir="SeedDMS" name="/">
|
<dir baseinstalldir="SeedDMS" name="/">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user