What is the difference between php: // input and php: // stdin

Similarly, what is the difference between php://outputand php://stdout?

I tried to figure out how the servers provide php://inputand php://output. The only way I could think of (given that php://output php://inputit php://outputdoes not depend on the mysterious php.ini file in accordance with this page in the manual ) would mean that stdinthey stdoutwould refer to the handle of the connection socket file. But then, to my chagrin, I found out that php://stdinthey php://stdoutwere also defined - apparently, in a different way.

Is it just redundant or are these file names actually referring to different things? Can someone tell me what is going on here?

+6
source share
1 answer

The difference is in which environment you should use them. php://stdin, php://stdoutand are php://stderrmapped directly to the corresponding POSIX file streams and are intended for use with the SAPI CLI. On the other hand, php://output php://inputthey php://outputare intended for use with SAPI websites.

Try running these two commands from the command line:

printf "foo" | php -r "var_dump(file_get_contents('php://stdin'));"

printf "foo" | php -r "var_dump(file_get_contents('php://input'));"

You will get the result as follows:

Command line code:1:
string(3) "foo"

Command line code:1:
string(0) ""

php://input , -SAPI, CGI mod_php, STDIN, . , POST ( php://input) php://stdin .

php://output , , echo . php://stdout , echo.

php://stderr , , , , .

0

Source: https://habr.com/ru/post/1620015/


All Articles