9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/phancap.htm
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/phancap.htm
30 * Run a shell command and check exit code.
32 * @param string $cmd Full command including parameters and options
33 * @param string $name Command name for exception
36 * @throws \Exception When the exit code is not 0
38 public static function run($cmd, $name)
40 exec($cmd . ' 2>&1', $arOutput, $exitcode);
42 //FIXME: do something with $arOutput
43 //echo implode("\n", $arOutput) . "\n";
44 throw new \Exception('Error running ' . $name, $exitcode);
49 * Let the command run for some time. Kill it if it did not exit itself.
51 * We use the GNU coreutils "timeout" utility instead of the pcntl
52 * extension since pcntl is disabled on mod_php.
54 * @param string $cmd Full command including parameters and options
55 * @param int $seconds Number of seconds after which the cmd is killed
56 * @param string $name Command name for exception
59 * @throws \Exception When the exit code is not 0
61 public static function runForSomeTime($cmd, $seconds, $name)
64 'timeout --signal=9 ' . $seconds . 's ' . $cmd,