Skip to content

Instantly share code, notes, and snippets.

@tsuchm
Last active May 3, 2020 10:20
Show Gist options
  • Save tsuchm/3e60f6795b8686005687e5fbc8adc57c to your computer and use it in GitHub Desktop.
Save tsuchm/3e60f6795b8686005687e5fbc8adc57c to your computer and use it in GitHub Desktop.
Patch to add timeout feature for http://web-console.org/
--- webconsole.php~
+++ webconsole.php
@@ -561,12 +561,27 @@
2 => array('pipe', 'w') // STDERR
);
- $process = proc_open($command . ' 2>&1', $descriptors, $pipes);
+ $process = proc_open(escapeshellcmd($command), $descriptors, $pipes);
if (!is_resource($process)) die("Can't execute command.");
// Nothing to push to STDIN
fclose($pipes[0]);
+ $timeout = time() + 3;
+ do {
+ $status = proc_get_status($process);
+ if (!$status['running']) break;
+ $timeleft = $timeout - time();
+ if ($timeleft <= 0) {
+ system('pkill -KILL -P '.$status['pid']);
+ break;
+ }
+ $read = array($pipes[1], $pipes[2]);
+ $write = null;
+ $exceptions = null;
+ stream_select($read, $write, $exceptions, $timeleft);
+ } while(!feof($pipes[1]) || !feof($pipes[2]));
+
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
@@ -576,7 +591,7 @@
// All pipes must be closed before "proc_close"
$code = proc_close($process);
- return $output;
+ return $output.$error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment