File: proc_open01.phpt

package info (click to toggle)
php5 5.6.33%2Bdfsg-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 157,872 kB
  • sloc: ansic: 756,065; php: 22,030; sh: 12,311; cpp: 8,771; xml: 6,179; yacc: 1,564; exp: 1,514; makefile: 1,467; pascal: 1,147; awk: 538; perl: 315; sql: 22
file content (69 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--TEST--
proc_open() regression test 1 (proc_open() leak)
--FILE--
<?php
$pipes = array(1, 2, 3);
$orig_pipes = $pipes;
$php = getenv('TEST_PHP_EXECUTABLE'); 
if ($php === false) {
	die("no php executable defined");
} 
$proc = proc_open(
	"$php -n",
	array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')),
	$pipes, getcwd(), array(), array('binary_pipes' => true)
);
if ($proc === false) {
	print "something went wrong.\n";
}
var_dump($pipes);
stream_set_blocking($pipes[1], FALSE);
$test_string = b"yay!\n";
fwrite($pipes[0], $test_string);
fflush($pipes[0]);
fclose($pipes[0]);
$cnt = '';
$n=0;
for ($left = strlen($test_string); $left > 0;) { 
	if (++$n >1000) {
	  print "terminated after 1000 iterations\n";
	  break;
	}
	$read_fds = array($pipes[1]);
	$write_fds = NULL;
	$exp_fds = NULL;
	$retval = stream_select($read_fds, $write_fds, $exp_fds, 5);
	if ($retval === false) {
		print "select() failed\n";
		break;
	}
	if ($retval === 0) {
		print "timed out\n";
		break;
	}
	$buf = fread($pipes[1], 1024);
	$cnt .= $buf;
	$left -= strlen($buf);
}
var_dump($cnt);
fclose($pipes[1]);
proc_close($proc);
var_dump($orig_pipes);
?>
--EXPECTF--
array(2) {
  [0]=>
  resource(%d) of type (stream)
  [1]=>
  resource(%d) of type (stream)
}
%unicode|string%(5) "yay!
"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}