kill cutycapt if it hangs
[phancap.git] / src / phancap / Executor.php
index 5b59094fd5419defae8da3cedc275b7403c759bd..f9962bbf7d5bde6f28abf5561b2929bb51b57288 100644 (file)
@@ -43,5 +43,23 @@ class Executor
             throw new \Exception('Error running cutycapt', $exitcode);
         }
     }
+
+    /**
+     * Let the command run for some time. Kill it if it did not exit itself.
+     *
+     * We use the GNU coreutils "timeout" utility instead of the pcntl
+     * extension since pcntl is disabled on mod_php.
+     *
+     * @param string $cmd Full command including parameters and options
+     *
+     * @return void
+     * @throws \Exception When the exit code is not 0
+     */
+    public static function runForSomeTime($cmd, $seconds)
+    {
+        return static::run(
+            'timeout --signal=9 ' . $seconds . 's ' . $cmd
+        );
+    }
 }
 ?>