Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
Use server_{input,output} for request input/output in CLI mode (#31)
Browse files Browse the repository at this point in the history
Summary:
`php://input` is never a real file handle, even in CLI mode. We should
change this now we don't need to be PHP-compatible, but for now,
workaround it by exposing the real STDIN.

This demonstrates the diference:

```
<?php
$f = fopen('php://stdin', 'r');
stream_set_blocking($f, false);
fgets($f);
var_dump(feof($f)); // false for php://stdin, true for php://input
```
Pull Request resolved: #31

Reviewed By: kmeht

Differential Revision: D13510875

Pulled By: kmeht

fbshipit-source-id: d0b335f7312a5cdc3dc1a2ce7af112a0be428d1d
  • Loading branch information
fredemmott committed Dec 19, 2018
1 parent 9ec62ca commit e819133
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/io/stdio.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ function server_input(): ReadHandle {
*
* @see requestOutput
*/
<<__Memoize>>
function request_output(): WriteHandle {
// php://output has differing eof behavior for interactive stdin - we need
// the php://stdout for interactive usage (e.g. repls)
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
if (\php_sapi_name() === "cli") {
return server_output();
}
return _Private\StdioHandle::requestOutput();
}

Expand All @@ -66,6 +74,14 @@ function request_error(): WriteHandle {
* In CLI mode, this is likely STDIN; for HTTP requests, it may contain the
* POST data, if any.
*/
<<__Memoize>>
function request_input(): ReadHandle {
// php://input has differing eof behavior for interactive stdin - we need
// the php://stdin for interactive usage (e.g. repls)
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
if (\php_sapi_name() === "cli") {
return server_input();
}
return _Private\StdioHandle::requestInput();
}

0 comments on commit e819133

Please sign in to comment.