1--TEST-- 2proc_open() with socket and pipe 3--FILE-- 4<?php 5 6function poll($pipe, $read = true) 7{ 8 $r = ($read == true) ? [$pipe] : null; 9 $w = ($read == false) ? [$pipe] : null; 10 $e = null; 11 12 if (!stream_select($r, $w, $e, null, 0)) { 13 throw new \Error("Select failed"); 14 } 15} 16 17function read_pipe($pipe): string 18{ 19 poll($pipe); 20 21 if (false === ($chunk = @fread($pipe, 8192))) { 22 throw new Error("Failed to read: " . (error_get_last()['message'] ?? 'N/A')); 23 } 24 25 return $chunk; 26} 27 28$cmd = [ 29 getenv("TEST_PHP_EXECUTABLE"), 30 __DIR__ . '/proc_open_sockets2.inc' 31]; 32 33$spec = [ 34 ['pipe', 'r'], 35 ['socket'] 36]; 37 38$proc = proc_open($cmd, $spec, $pipes); 39 40var_dump(stream_set_blocking($pipes[1], false)); 41 42printf("STDOUT << %s\n", read_pipe($pipes[1])); 43printf("STDOUT << %s\n", read_pipe($pipes[1])); 44 45fwrite($pipes[0], 'done'); 46fclose($pipes[0]); 47 48printf("STDOUT << %s\n", read_pipe($pipes[1])); 49 50?> 51--EXPECTF-- 52bool(true) 53STDOUT << hello 54STDOUT << world 55STDOUT << DONE 56