MCPcopy Create free account
hub / github.com/Bloggify/github-calendar / execute

Function execute

proxy-self-hosted/util/index.php:20–66  ·  view source on GitHub ↗

https://stackoverflow.com/questions/3407939/shell-exec-timeout-management-exec

($cmd, $stdin=null, &$stdout, &$stderr, $timeout=false)

Source from the content-addressed store, hash-verified

18
19 // https://stackoverflow.com/questions/3407939/shell-exec-timeout-management-exec
20 function execute($cmd, $stdin=null, &$stdout, &$stderr, $timeout=false)
21 {
22 $pipes = array();
23 $process = proc_open(
24 $cmd,
25 array(array('pipe','r'),array('pipe','w'),array('pipe','w')),
26 $pipes
27 );
28 $start = time();
29 $stdout = '';
30 $stderr = '';
31
32 if(is_resource($process))
33 {
34 stream_set_blocking($pipes[0], 0);
35 stream_set_blocking($pipes[1], 0);
36 stream_set_blocking($pipes[2], 0);
37 fwrite($pipes[0], $stdin);
38 fclose($pipes[0]);
39 }
40
41 while(is_resource($process))
42 {
43 //echo ".";
44 $stdout .= stream_get_contents($pipes[1]);
45 $stderr .= stream_get_contents($pipes[2]);
46
47 if($timeout !== false && time() - $start > $timeout)
48 {
49 proc_terminate($process, 9);
50 return 1;
51 }
52
53 $status = proc_get_status($process);
54 if(!$status['running'])
55 {
56 fclose($pipes[1]);
57 fclose($pipes[2]);
58 proc_close($process);
59 return $status['exitcode'];
60 }
61
62 usleep(100000);
63 }
64
65 return 1;
66 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…