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