1--TEST-- 2proc_open() with output socketpairs 3--SKIPIF-- 4<?php 5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 6?> 7--FILE-- 8<?php 9 10$cmd = [ 11 getenv("TEST_PHP_EXECUTABLE"), 12 __DIR__ . '/proc_open_sockets1.inc' 13]; 14 15$spec = [ 16 ['null'], 17 ['socket'], 18 ['socket'] 19]; 20 21$proc = proc_open($cmd, $spec, $pipes); 22 23foreach ($pipes as $pipe) { 24 var_dump(stream_set_blocking($pipe, false)); 25} 26 27while ($pipes) { 28 $r = $pipes; 29 $w = null; 30 $e = null; 31 32 if (!stream_select($r, $w, $e, null)) { 33 throw new Error("Select failed"); 34 } 35 36 foreach ($r as $i => $pipe) { 37 if (!is_resource($pipe) || feof($pipe)) { 38 unset($pipes[$i]); 39 continue; 40 } 41 42 $chunk = @fread($pipe, 8192); 43 44 if ($chunk === false) { 45 throw new Error("Failed to read: " . (error_get_last()['message'] ?? 'N/A')); 46 } 47 48 if ($chunk !== '') { 49 echo "PIPE {$i} << {$chunk}\n"; 50 } 51 } 52} 53 54?> 55--EXPECT-- 56bool(true) 57bool(true) 58PIPE 1 << hello 59PIPE 2 << SOME ERROR 60PIPE 1 << world 61