-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes GH-5777.
- Loading branch information
Showing
10 changed files
with
300 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
echo "hello"; | ||
sleep(1); | ||
fwrite(STDERR, "SOME ERROR"); | ||
sleep(1); | ||
echo "world"; |
56 changes: 56 additions & 0 deletions
56
ext/standard/tests/general_functions/proc_open_sockets1.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--TEST-- | ||
proc_open() with output socketpairs | ||
--FILE-- | ||
<?php | ||
|
||
$cmd = [ | ||
getenv("TEST_PHP_EXECUTABLE"), | ||
__DIR__ . '/proc_open_sockets1.inc' | ||
]; | ||
|
||
$spec = [ | ||
['null'], | ||
['socket'], | ||
['socket'] | ||
]; | ||
|
||
$proc = proc_open($cmd, $spec, $pipes); | ||
|
||
foreach ($pipes as $pipe) { | ||
var_dump(stream_set_blocking($pipe, false)); | ||
} | ||
|
||
while ($pipes) { | ||
$r = $pipes; | ||
$w = null; | ||
$e = null; | ||
|
||
if (!stream_select($r, $w, $e, null, 0)) { | ||
throw new Error("Select failed"); | ||
} | ||
|
||
foreach ($r as $i => $pipe) { | ||
if (!is_resource($pipe) || feof($pipe)) { | ||
unset($pipes[$i]); | ||
continue; | ||
} | ||
|
||
$chunk = @fread($pipe, 8192); | ||
|
||
if ($chunk === false) { | ||
throw new Error("Failed to read: " . (error_get_last()['message'] ?? 'N/A')); | ||
} | ||
|
||
if ($chunk !== '') { | ||
echo "PIPE {$i} << {$chunk}\n"; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
bool(true) | ||
PIPE 1 << hello | ||
PIPE 2 << SOME ERROR | ||
PIPE 1 << world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
echo "hello"; | ||
sleep(1); | ||
echo "world"; | ||
|
||
echo strtoupper(trim(fgets(STDIN))); |
67 changes: 67 additions & 0 deletions
67
ext/standard/tests/general_functions/proc_open_sockets2.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--TEST-- | ||
proc_open() with IO socketpairs | ||
--FILE-- | ||
<?php | ||
|
||
function poll($pipe, $read = true) | ||
{ | ||
$r = ($read == true) ? [$pipe] : null; | ||
$w = ($read == false) ? [$pipe] : null; | ||
$e = null; | ||
|
||
if (!stream_select($r, $w, $e, null, 0)) { | ||
throw new \Error("Select failed"); | ||
} | ||
} | ||
|
||
function read_pipe($pipe): string | ||
{ | ||
poll($pipe); | ||
|
||
if (false === ($chunk = @fread($pipe, 8192))) { | ||
throw new Error("Failed to read: " . (error_get_last()['message'] ?? 'N/A')); | ||
} | ||
|
||
return $chunk; | ||
} | ||
|
||
function write_pipe($pipe, $data) | ||
{ | ||
poll($pipe, false); | ||
|
||
if (false == @fwrite($pipe, $data)) { | ||
throw new Error("Failed to write: " . (error_get_last()['message'] ?? 'N/A')); | ||
} | ||
} | ||
|
||
$cmd = [ | ||
getenv("TEST_PHP_EXECUTABLE"), | ||
__DIR__ . '/proc_open_sockets2.inc' | ||
]; | ||
|
||
$spec = [ | ||
['socket'], | ||
['socket'] | ||
]; | ||
|
||
$proc = proc_open($cmd, $spec, $pipes); | ||
|
||
foreach ($pipes as $pipe) { | ||
var_dump(stream_set_blocking($pipe, false)); | ||
} | ||
|
||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
|
||
write_pipe($pipes[0], 'done'); | ||
fclose($pipes[0]); | ||
|
||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
|
||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
bool(true) | ||
STDOUT << hello | ||
STDOUT << world | ||
STDOUT << DONE |
55 changes: 55 additions & 0 deletions
55
ext/standard/tests/general_functions/proc_open_sockets3.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--TEST-- | ||
proc_open() with socket and pipe | ||
--FILE-- | ||
<?php | ||
|
||
function poll($pipe, $read = true) | ||
{ | ||
$r = ($read == true) ? [$pipe] : null; | ||
$w = ($read == false) ? [$pipe] : null; | ||
$e = null; | ||
|
||
if (!stream_select($r, $w, $e, null, 0)) { | ||
throw new \Error("Select failed"); | ||
} | ||
} | ||
|
||
function read_pipe($pipe): string | ||
{ | ||
poll($pipe); | ||
|
||
if (false === ($chunk = @fread($pipe, 8192))) { | ||
throw new Error("Failed to read: " . (error_get_last()['message'] ?? 'N/A')); | ||
} | ||
|
||
return $chunk; | ||
} | ||
|
||
$cmd = [ | ||
getenv("TEST_PHP_EXECUTABLE"), | ||
__DIR__ . '/proc_open_sockets2.inc' | ||
]; | ||
|
||
$spec = [ | ||
['pipe', 'r'], | ||
['socket'] | ||
]; | ||
|
||
$proc = proc_open($cmd, $spec, $pipes); | ||
|
||
var_dump(stream_set_blocking($pipes[1], false)); | ||
|
||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
|
||
fwrite($pipes[0], 'done'); | ||
fclose($pipes[0]); | ||
|
||
printf("STDOUT << %s\n", read_pipe($pipes[1])); | ||
|
||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
STDOUT << hello | ||
STDOUT << world | ||
STDOUT << DONE |
Oops, something went wrong.