Skip to content

Commit 6079f27

Browse files
committed
calculate columns only once
when using the progress bar, `tput` would be called really often, leading to errors such as "exec(): Unable to fork"
1 parent e187756 commit 6079f27

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/cli/Shell.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ class Shell {
2424
* @todo Test on more systems.
2525
*/
2626
static public function columns() {
27-
if (stripos(PHP_OS, 'indows') === false) {
28-
return (int) exec('/usr/bin/env tput cols');
27+
static $columns;
28+
29+
if ( null === $columns ) {
30+
if (stripos(PHP_OS, 'indows') === false) {
31+
$columns = (int) exec('/usr/bin/env tput cols');
32+
}
33+
34+
if ( !$columns ) {
35+
$columns = 80; // default width of cmd window on Windows OS, maybe force using MODE CON COLS=XXX?
36+
}
2937
}
30-
return 80; // default width of cmd window on Windows OS, maybe force using MODE CON COLS=XXX?
38+
39+
return $columns;
3140
}
3241

3342
/**

0 commit comments

Comments
 (0)