diff --git a/SeedDMS_Preview/Preview/Previewer.php b/SeedDMS_Preview/Preview/Previewer.php index b993024c0..2532743e8 100644 --- a/SeedDMS_Preview/Preview/Previewer.php +++ b/SeedDMS_Preview/Preview/Previewer.php @@ -68,6 +68,39 @@ class SeedDMS_Preview_Previewer { ); } + static function execWithTimeout($cmd, $timeout=2) { /* {{{ */ + $descriptorspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("pipe", "w") + ); + $pipes = array(); + + $timeout += time(); + $process = proc_open($cmd, $descriptorspec, $pipes); + if (!is_resource($process)) { + throw new Exception("proc_open failed on: " . $cmd); + } + + $output = ''; + do { + $timeleft = $timeout - time(); + $read = array($pipes[1]); + stream_select($read, $write = NULL, $exeptions = NULL, $timeleft, NULL); + + if (!empty($read)) { + $output .= fread($pipes[1], 8192); + } + } while (!feof($pipes[1]) && $timeleft > 0); + + if ($timeleft <= 0) { + proc_terminate($process); + throw new Exception("command timeout on: " . $cmd); + } else { + return $output; + } + } /* }}} */ + /** * Set a list of converters * @@ -146,7 +179,11 @@ class SeedDMS_Preview_Previewer { } */ if($cmd) { - exec($cmd); + //exec($cmd); + try { + self::execWithTimeout($cmd); + } catch(Exception $e) { + } } return true; } diff --git a/SeedDMS_Preview/package.xml b/SeedDMS_Preview/package.xml index 123aa130e..2ce89a37d 100644 --- a/SeedDMS_Preview/package.xml +++ b/SeedDMS_Preview/package.xml @@ -11,8 +11,8 @@ uwe@steinmann.cx yes - 2015-02-13 - + 2015-08-08 + 1.1.4 1.1.4 @@ -23,7 +23,8 @@ GPL License -Converters to create preview images are no longer fixed. Those which has been hardcoded before remain the predefined converters, but they can also be changed. +- Converters to create preview images are no longer fixed. Those which has been hardcoded before remain the predefined converters, but they can also be changed. +- command for creating the preview will be called with a given timeout